[TYPO3-dev] WARNING: Is Prototype affecting the inbuilt JavaScript Array and Object types?

Peter Klein peter at umloud.dk
Fri Sep 15 15:20:35 CEST 2006


"Martin Kutschker" <Martin.Kutschker at n0spam-blackbox.net> skrev i en 
meddelelse news:mailman.1.1158325800.31104.typo3-dev at lists.netfielders.de...

> Reading the mentioned doc I take it that every object is an associative 
> array. So a numeric array can take associative values which it can take 
> because an Array extends Object.
>
> x=new Array('n','m');
> x['a']='b';
> alert(x['a']);
> alert(x.length);
> alert(x[1]);
>
> This code shows 'b' (from the associative array), 2 (length of the numeric 
> array) and 'm' (from the numeric array),
>
> So x is still an Array even after I set an "associative value".
>

Yes, but x['a']='b' is not part of the array, but instead a property of "x" 
(as an Array is also an Object).
That's why length only returns a value of 2 and not 3. (as length is only 
available for Arrays.)

So when you access it like "alert(x['a'])", you are accessing it as an 
Object, and reads "x" 's properties (in this case, the "a" property).

-- 
Peter Klein/Umloud Untd







More information about the TYPO3-dev mailing list