javascript中对象的创建-工厂模式
function createPerson(name,age,job){ var o=new Object(); o.name=name; o.age=age; o.job=job; o.sayName=function(){ alert(this.name); }; return o; } var person1=createPerson("null",25,"Software Engineer"); var person2=createPerson("null2",250,"Software Engineer");
但是,你知道对象类型吗?
alert(person1 instanceof createPerson); //false alert(person1 instanceof Object);//true