JavaScript工厂模式代码

时间:2024-05-07 16:36:50

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;

}

//可以无数次调用createPerson函数

var person1=createPerson("GReg",20,"sofwear engineer");

var person2=createPerson("xiaofei",21,"jixie gongchengshi");

相关文章