单例模式
单列模式,一个构造函数一生只有一个实例
const Person = (function () {
function Person(name, age) {
this.name = name;
this.age = age;
}
let instance = null;
return function singTom(arg) {
if (!instance) instance = new Person(...arg);
return instance;
};
})();
const p1=new Person(['zhang',33]);
const p2=new Person(['li',33]);
console.log(p1,p2);
console.log(p1==p2);//true