1.创建Object实例的方式有两种:一种是通过new Object():
var person = new Object();
person.name = "brancepeng";
person.age= 12;
console.log(person ); //输出 Object {name: "brancepeng", age: 12}
2.另一种是对象字面量表示法;var person = {name : "brancepeng" , age : 12 };
虽然Object实例不具备多少功能,但是对于在程序中存储数据和传输数据是非常有用.其中,字面量对象是向函数传输大量参数的首选方式.eg:
var person1={ name : "brancepeng", age : 21 }; var person2 = {name : "Hanmeimei"};
function displayInfo(args){ var out = ""; if (typeof args.name == "string") { out +="Name : "+args.name +"\n"; } if (typeof args.age == "number") { out +="Age : "+args.age+"\n"; } alert(out); } displayInfo(person1);displayInfo(person2);