1. 通过构造函数obj来创建
var obj = new object();
obj.name = "xm";
obj.age = 19;
obj.eat = function(){
}
2. 字面量创建
var obj ={
name: " xm",
age: 19,
eat: function(){}
}
3.工厂函数
function students(name,age){
var obj ={
name: " xm",
age: 19,
eat: function(){}
}
return obj;
}
var xm = student("xm",19);
var xh = student("xh",19);
// 可以批量创建但是类型不明确
4. 自定义构造函数创建
function students(name,age){
this.name = name;
this.age = age;
}
var xm = new student("xm",19);