Last active
July 14, 2016 17:43
-
-
Save martin-sweeny/3754cb5786e8354efa0081cdeb1e62ce 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
/** | |
* Example Singleton constructor. | |
* I wish this was extendable but you gotta copy/paste the 2 lines into any object you want to be a Singleton | |
* | |
* @returns {*} | |
* @constructor | |
*/ | |
function Singleton () { | |
if ( arguments.callee._singletonInstance ) return arguments.callee._singletonInstance; | |
arguments.callee._singletonInstance = this; | |
} |
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
var Thing1 = new Singleton(); | |
var Thing2 = new Singleton(); | |
Thing1.foo = 'bar'; | |
Thing2.foo; // 'bar' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment