1理解对象
1)创建对象
方法1
var person=new Object();
person.name="fuck";
person.age=16;
方法2
var person={
name:"fuck",
age:12
}
工厂模式
function People (name,age) { var o=new Object(); o.name=name; o.age=age; o.sayName=function () { return this.name; } return o; } var a=People("huangjiabing","23");
构造函数模式
function People (name,age) { this.name=name; this.age=age; this.sayName=function () { return this.name; }; } var a=new People("huangjiabing",23);
a instanceof Object;//true
a instanceof People;//true
在另一个作用域中调用构造函数
var o=new Object();
People.call(o,"huanggabing",23);//很关键
alert(o.sayName());