I'm a little new to JavaScript. I've used it here and there on the client-side for a while, but now I am adventuring into server-side Javascript. This question is about Javascript objects, regarding their creation and the efficient definition of their properties.
I've seen (several times) that creating an object as var o = {};
is now preferred over var o = new Object();
for performance reasons. Are there differences in performance in how you add properties to an object?
For instance, is there any difference in performance between this situation:
var o = {
thing1: "yardigooven",
thing2: "goovenyardi",
};
and this situation?:
var o = {};
o.thing1 = "yardigooven";
o.thing2 = "goovenyardi";
I'm assuming the first case is preferred, but I want to make sure before I write all of my object definitions that way.
Thanks.
See Question&Answers more detail:os