You cannot access the first properties of an object without instantiating it, i.e. using the new keyword:
var myUser = new User() ; document.write(myUser.id) ;
The second object is the object literal, which is available without an instance, since it was already created during analysis.
The difference comes into play if you want to use prototypical inheritance to create a new object based on the old one. Writing an object literal is probably easier to understand and a more appropriate template if you have a fairly compact code base. However, prototyping comes in handy if you want to create a new object by adding an existing object to another object without overwriting the magnified object:
ipUser.prototype = User ; ipUser.ip = "128.0.0.1" ;
In your case, this difference may not seem impressive, but you have to imagine how much redundant code you get if you created a different object literal for each small addition to the original object.
Take a look at the Mozilla Developer Center page on JavaScript objects, if you have additional questions, this is very well defined: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference:Global_Objects:Object .
Hth
Fk82
source share