October 2006
Intermediate to advanced
288 pages
5h 55m
English
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 HadlockAs 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 ...
Read now
Unlock full access