As some of the other answers here indicate, it is an example of object literal notation. An object can be declared like so:
var myObj = new Object();
However, it can also be declared with object literal notation, like so:
var myObj = { };
When using object literal syntax, one can immediately add methods and properties inside the open and closing braces using the syntax name : value. For example:
var myObj = {
name: 'Dave',
id: 42,
SomethingHere: function() {
/* function body */
}
};
alert(myObj.name); // Displays Dave
alert(myObj.id); // Displays 42
myObj.SomethingHere(); // Executes method SomethingHere
"SomethingHere," in this case is a "method," meaning that it is a function that is a member of an object. It's significance lies in the special variable this. In the following two function definitions, this refers to the browser window variable (assuming that are running the code in a browser):
function foo() {
/* this.document refers to window.document */
/* this.location refers to window.location*/
}
var bar = function() {
/* Same as above, just a different syntax for declaring the function.
/* this.document refers to window.document */
/* this.location refers to window.location*/
}
In this example, however, this refers to the enclosing object, myObj:
var myObj = {
name = 'Dave',
id = 42,
myMethod: function() {
/* this.name refers to the name property of myObj, i.e., 'Dave' */
/* this.id refers to the id property of myObj, i.e., 42 */
/* this.location is undefined */
/* this.document is undefined */
}
};