Last active
January 2, 2016 16:49
-
-
Save kamiyam/8332542 to your computer and use it in GitHub Desktop.
Always the only instance
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
do(w=window,d=document) -> | |
# log output | |
log = -> | |
if (typeof console isnt 'undefined') | |
console.log.apply(console, arguments); | |
## implements | |
class Singleton | |
constructor: ( name ) -> | |
@name = name | |
hello: -> | |
log name | |
## end class Singleton | |
instance = null | |
w.Singleton = (name) -> | |
if ( instance ) | |
instance | |
else | |
instance = new Singleton(name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment