Sunday, 20 November 2011

Javascript Object Literals


// Object Literals

timObject = {
 property1 : "Hello",
 property2 : "MmmMMm",
 property3 : ["mmm", 2, 3, 6, "kkk"],
 method1 : function(){alert("Method had been called" + this.property1)}
};

timObject.method1();
alert(timObject.property3[2]) // will yield 3

OR------------------------
 
 
 
 
 
person = new Object()
person.name = "Tim Scarfe"
person.height = "6Ft"

person.run = function() {
 this.state = "running"
 this.speed = "4ms^-1"
}
 
 
http://mckoss.com/jscript/object.htm 

No comments:

Post a Comment