Wednesday, April 11, 2012

Object-Oriented JavaScript

Advanced Web Applications With Object-Oriented JavaScript @ MSDN

In JavaScript, objects are just collections of name/value pairs
—think of a JavaScript object as a dictionary with string keys

var userObject = new Object();
userObject.lastLoginTime = new Date();
alert(userObject.lastLoginTime);
does exactly the same thing as this:
var userObject = {}; // equivalent to new Object()
userObject["lastLoginTime"] = new Date();
alert(userObject["lastLoginTime"]);
We can also define the lastLoginTime property directly within userObject’s definition like this:
var userObject = { "lastLoginTime": new Date() };
alert(userObject.lastLoginTime);

No comments: