We have 2 Singleton:
let Singleton = (() => {
let instance;
function init() {
return instance || (instance = this);
}
return init;
})();
let s = new Singleton();
let s2 = new Singleton();
console.log(s == s2);
let Singleton2 = (() => {
let instance;
let init = () => {
return instance || (instance = this);
}
return init;
})();
let s1 = new Singleton2();
let s12 = new Singleton2();
console.log(s1 == s12);
first one works like it suppose to, but second one give me: Uncaught TypeError: Singleton2 is not a constructor
can some body tell me why the second Singleton is not a constructor? thank you for your time.