I'm writing javascript singleton class and want to use singleton pattern like this:
function TestClass() {
var self = TestClass.prototype;
if (self.instance) return self.instance;
self.instance = this;
//methods and props declarations
}
var x = new TestClass;
var y = new TestClass;
console.log(x === y); // true
It seems to be worked as i expected, but i worry about memory leaks. So i decided to ask experts, if it is the correct solution