JS创建对象
JS创建对象
1. 对象字面量
1 var persopn = {name: 'jany', age:12}
2. 通过object创建
1 var person = new Object(); 2 person.name = 'jany'; 3 person.age = 13;
3. 构造函数创建对象
1 function Person(name,age) { 2 this.name = name; 3 this.age = age; 4 } 5 var p = new Person('hany',12)
注意:要使用new操作符
4. Object.create()
var p = Object.create({name:'jany',age:12})