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

 

 

posted on 2014-04-08 22:42  nU||  阅读(182)  评论(0编辑  收藏  举报

导航