$(function () {
Factory('Java','TEXT')
});
var Factory=function(type,text){
if(this instanceof Factory){
var s=new this[type](text);
return s
}else{
return new Factory(type,text);
}
};
Factory.prototype= {
Java:function (text) {
alert("JAVA")
},
JavaScript:function(text){
alert("JavaScript")
},
UI:function (text) {
alert("UI")
}
}
這種模式好在降耦合,比簡單工廠模式方便。
重點理解這個
new this[type]()
程序調用是這樣的!