美文网首页
工厂模式创建对象

工厂模式创建对象

作者: 宠着我家刘蕊 | 来源:发表于2018-12-10 14:50 被阅读0次

functionPerson(name,age,job)

{

//创建一个空对象

varo = {};

 o.name = name; 

o.age = age; 

o.job = job; 

o.showName =function(){ alert(this.name);

 };

 o.showName =function(){ alert(this.age); 

}; 

o.showName =function(){ alert(this.job); 

};returno; 

}

varTom = Person('tom',18,'程序员'); 

Tom.showName();

functionPerson(name,age,job){

this.name = name;

this.age = age;

this.job = job;

this.showName =function(){ 

alert(this.name); 

};

this.showAge =function(){

 alert(this.age); 

};t

his.showJob =function(){

 alert(this.job);

 }; 

}varBob =newPerson('bob',18,'产品汪'); 

Bob.showName();

相关文章

网友评论

      本文标题:工厂模式创建对象

      本文链接:https://www.haomeiwen.com/subject/pigrhqtx.html