Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created November 16, 2012 09:24
Show Gist options
  • Save alanshaw/4085837 to your computer and use it in GitHub Desktop.
Save alanshaw/4085837 to your computer and use it in GitHub Desktop.
Lazy singleton class instance function
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