设计模式可分为单例模式、工厂模式、构造函数模式、发布订阅模式等等,下面通过一个简单例子解释一下工厂模式创建对象的方式
function createObject(name,age) {
var obj=new Object();
obj.name=name;
obj.age=age;
obj.eat=function () {
console.log("喜欢吃火锅");
};
return obj;
}
var lut = createObject('甜甜圈',23);
lut.eat();
console.log(lut);