Created
March 17, 2018 14:13
-
-
Save linx4200/0cfd1cd64797e1ae177d391e3763bac1 to your computer and use it in GitHub Desktop.
【Factory】安全的工厂方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 安全模式创建的工厂类 | |
var Factory = function(type, content) { | |
if (this instanceof Factory) { | |
return new this[type](content); | |
} else { | |
return new Factory(type, content); | |
} | |
} | |
// 工厂原型中设置创建所有类型数据对象的基类 | |
Factory.prototype = { | |
Java: function(content) { | |
// ... | |
}, | |
JavaScript: function() { | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment