Created
August 25, 2016 08:19
-
-
Save frontdevops/4b8a8768fe1d3916e96cead01cde74a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(g){ | |
/** @type {SingletonConstructor} */ | |
var instance; | |
g.Singleton = function() { | |
if (instance !== void 0) return instance; | |
return instance = this; | |
}; | |
g.Singleton.prototype.foo = 123; | |
})(window||global); | |
var obj1 = new Singleton; | |
var obj2 = new Singleton; | |
console.log(obj2.foo === 123); | |
obj1.foo = 456; | |
console.log(obj2.foo === 456); | |
console.log(obj1 === obj2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment