Literal Notation and Object Constructors in JavaScript

Putting something up here again for my own reference. The comments on this article are the part that interested me. I like using object literal notation and wanted to know if it would be possible to write a reusable object constructor in literal notation. From all the discussion, it seems that making object constructors is best still done using a prototype function. Object literal notation is great for creating a single instance of an object but not ideal for creating an object constructor that can be used to create multiple instances of an object. If anyone knows differently, I'd be interested.

JSON for the Masses

Edit: Here are two sites that offer utilities to create constructor classes from an object in literal notation:

Leave a Reply

If you plan on posting code, please enclose it in the <pre><code> tags to preserve formatting. If your code block includes XHTML tags, please use Postable.