Literal notation is a more complex way of defining objects with JavaScript and is supported in JavaScript 1.2 and above. This approach is a sort of shorthand way of creating objects, which makes them easy to build but a bit hard to read because of the unique syntax that they require. Here is a sample of creating the same object (with the literal notation approach) we created with the new operator. employee = { id : 001; firstName : "Kris"; lastName : "Hadlock"; getFullName : function() { return this.firstName + " " + this.lastName; } } alert(employee.getFullName); // Results: Kris Hadlock As you can see, this approach is easy to create, but could be rather hard to manage if we were to add a lot of methods and properties. Don't get me wrong, thoughthis is a viable solution, and I wouldn't necessarily recommend against it. It's just that I personally prefer to use a more familiar syntax. |