November 22, 2006

Javascript Object Literals

For a while now I've been experimenting with the dojo toolkit. I have been puzzling over what the following meant.

var something =
{ somename: "some value",
anothername: "another value",
more: function () { alert("called"); }

It is hard to come up with a search query for this. At first I thought it might be some sort of dictionary or hash table shorthand. However, I finally found that it was an object declaration shorthand and is equivilent to

var something = new Object();
something.somename = "some value";
something.anothername = "another value";
something.more = function () { alert("called"); };

No comments: