As some other answers show, this is an example of object notation. An object can be declared as follows:
var myObj = new Object();
However, it can also be declared with an object literal record, for example:
var myObj = { };
When using object literal syntax, you can immediately add methods and properties inside the open and close curly braces using the syntax name: value. For instance:
var myObj = { name: 'Dave', id: 42, SomethingHere: function() { } }; alert(myObj.name);
"SomethingHere", in this case, is a "method", which means that it is a function that is a member of the object. The special variable this has this value. In the following two function definitions, this refers to a browser window variable (assuming code is executed in the browser):
function foo() { } var bar = function() { }
In this example, however, this one refers to the enclosing object, myObj:
var myObj = { name = 'Dave', id = 42, myMethod: function() { } };
dgvid source share