1.简单工厂
现在生产面包,巧克力,牛奶
function Factory(price,name){
if (this instanceof Factory) {
let s = this[name](price);
} else {
return new Factory(price,name)
}
}
undefined
Factory.prototype = {
'getNiu':function(price){
alert('生产牛奶')
},
'getMinabao':function(price){
alert('生产面包')
},
'getJkeo':function(price){
alert('生产巧克力')
}
}
Factory(22,'getNiu')
Factory(22,'getJkeo')
工厂模式

网友评论