Skip to content

Instantly share code, notes, and snippets.

@linx4200
Created March 17, 2018 14:13
Show Gist options
  • Save linx4200/0cfd1cd64797e1ae177d391e3763bac1 to your computer and use it in GitHub Desktop.
Save linx4200/0cfd1cd64797e1ae177d391e3763bac1 to your computer and use it in GitHub Desktop.
【Factory】安全的工厂方法
// 安全模式创建的工厂类
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