Closed Thread Icon

Topic awaiting preservation: why this isn't working? isn't it standard? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8318" title="Pages that link to Topic awaiting preservation: why this isn&amp;#039;t working? isn&amp;#039;t it standard? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: why this isn&#039;t working? isn&#039;t it standard? <span class="small">(Page 1 of 1)</span>\

 
lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-19-2002 10:55

I was surprised to see that this code doesn't work on IE5 but works on IE6!

var x = {'obj1':[1,2,3], 'obj2':[2,3,4], 44:['hey', 'ho!']}


IE5 needs 'x' to be defined line by line for each element as it seems...
x = new Object;
x['obj']=[1,2,3]
.
.
.
// for IE5

is that true or i have a problem in my initial object construct?

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 09-19-2002 17:07

shouldn't it be:

var x = {'obj1':[1,2,3]; 'obj2':[2,3,4]; 44:['hey', 'ho!']}

with semi-colons for delimiters?

I don't really understand what you're trying to do, somewhere between a hash and an array, methinks...


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-19-2002 17:13

He's defining an object using the literal syntax. Just like an array can be defined with

myarray = [1,2,3,4,5];

an object can be defined with

myobject = {prop:'value', prop2:'value'};

Lallous, two problems with your script:
1. the property names shouldn't be quoted. They're not strings, they're properties... just like the x in 'var x' isn't quoted, obj1 and obj2 shouldn't be quoted.
2. you can't have a number like 44 be a property. All variables/properties must begin with a letter or underscore.

The correct assignment would be:

var x = {obj1:[1,2,3], obj2:[2,3,4], obj3:['hey', 'ho!']}

The reason x['obj'] = [1,2,3] works is because the [] operators take a string and convert it into a property. The object literal syntax doesn't do that.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-20-2002 00:58

Hi Slime,

weird...the 'obj1' as property name works as quoted! I'll try that with IE5 but unquoted.
as for the property as numbers...I have been using these as a mean of key indexed array as in php, and they have been working just fine!

as I said before too, that if defined on seperate lines (not literal) for both quoted properties names and numeric properties, they all work.



lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-23-2002 15:41

After testing on IE5

quote:
1. the property names shouldn't be quoted. They're not strings, they're properties... just like the x in 'var x' isn't quoted, obj1 and obj2 shouldn't be quoted.


they work quoted just fine when quoted/unquoted.

2. you can't have a number like 44 be a property. All variables/properties must begin with a letter or underscore.
You're right about numbers in ie5 and this case.
But they will work if you quote them as: {'55':[1,2,3]}

that's all.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-23-2002 18:20

Ah, but what works in Intenet Explorer rarely coincides with what's *allowed*. =)

My javascript book doesn't mention putting quotes around the properties in object literals, so I'm making the assumption that they're not allowed. Someone could check the ECMA spec if they're really interested =)

« BackwardsOnwards »

Show Forum Drop Down Menu