[thelist] [javascript] object literal question

Matt Warden mwarden at gmail.com
Thu Mar 9 05:59:06 CST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

liorean wrote:
>>>All objects are in effect
>>>associative arrays in JavaScript.
>>
>>Not quite. Object properties are implemented as an associative array (as
>>they are in many languages, whether the languages expose that fact to
>>the programmer or not), but an object is not an array (but, of course,
>>an array is an object).
> 
> 
> Well, I don't agree on this. The object and the array are essentially
> the same in implementation.

Maybe they are essentially or effectively the same, but what I am saying
is that they are not the same.

Array.prototype.foobar = function() { alert('hi'); }
(new Array()).foobar(); // will work
(new Object()).foobar(); // won't work

vs.

Object.prototype.foobar = function() { alert('hi'); }
(new Object()).foobar(); // will work
(new Array()).foobar(); // will work

> Well, one could argue that JavaScript doesn't have any array type
> at all if one wish. They are after all hash-tables or some
> variation of linked-lists in their implementation and not really
> arrays...

Again, this is the same in many languages, like PHP. These other
languages just don't smack you in the face with it by allowing you to
syntactically treat object properties as hash keys like you can in
JavaScript.

- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEEBiKrI3LObhzHRMRAopMAKCn72tu0z46rA9ldwOTt8X4TK/fQgCgwHgq
oZ5nFsid3iJPfTILKeddEMs=
=U0P3
-----END PGP SIGNATURE-----



More information about the thelist mailing list