创建对象:
1,创建单个对象
1,字面量
var obj = {};
2, 构造函数
var obj = new Object();
2,批量创建对象
1,工厂函数
function CreatPerson () {
var obj = {};
return obj;
}
function Person(name,age,desc) {
var obj = {
name: name,
age: age,
desc: desc,
say: function () {
console.log('大家吼,我系' + this.name)
}
}
return obj;
}
var xm = Person('小明', 18, '好看');
var xl = Person('小丽', 20, '美丽')
2, 自定义构造函数
function Dog (name,age) {
this.name = name;
this.age = age;
say:functios () {
cosole.log('二五五')
}
}
var er = new Dog('二哈', 3);
var td = new Dog('泰迪', 2)