Created
November 16, 2012 09:24
-
-
Save alanshaw/4085837 to your computer and use it in GitHub Desktop.
Lazy singleton class instance function
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
class Foo | |
@instance: (=> | |
instance = null | |
=> | |
instance = new @() if not instance | |
instance | |
)() | |
singletonFoo = Foo.instance() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment