Created
August 7, 2010 02:36
-
-
Save yuya-takeyama/512354 to your computer and use it in GitHub Desktop.
Singleton Object in JavaScript
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 Singleton = (function () { | |
var | |
obj = {}, | |
id, | |
init, | |
get_instance, | |
get_id; | |
init = function () { | |
id = Math.random(); | |
}; | |
obj.get_instance = function () { | |
if (typeof id === 'undefined') { | |
init(); | |
} | |
return obj; | |
}; | |
obj.get_id = function () { | |
return id; | |
}; | |
return obj; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment