ECMA-262把对象定义为:“无序属性的集合,其属性可以包含基本值、对象或者函数。”
Object方式创建对象:
var person = new Object();
person.name = "Nicholas";
person.age = 29;
person.job = "Software Engineer";
person.sayName = function(){
alert(this.name);
};
字面量方式创建对象:
var person = {
name: "Nicholas",
age: 29,
job: "Software Engineer",
sayName: function(){
alert(this.name);
}
};