Tuesday, February 28, 2012

JavaScript Object Literal

JavaScript Object Literal: "What is an object literal? In nontechnical terms, it is a means of containing a lot of data in one tidy package. It is a comma separated list of name value pairs wrapped in curly braces. In JavaScript an object literal is declared or defined as follows:

var myObject = {}
An object literal with a few properties, from a Rotating Images example:

var myRotator = {
path: 'images/',
speed: 4500,
images: ["smile.gif", "grim.gif", "frown.gif", "bomb.gif"]
Object literals are used as a means of encapsulating data, avoiding the use of global variables which can cause problems when combining code.


'via Blog this'