Skip to content

Instantly share code, notes, and snippets.

@algirdasrascius
Created May 26, 2011 17:40
Show Gist options
  • Save algirdasrascius/993592 to your computer and use it in GitHub Desktop.
Save algirdasrascius/993592 to your computer and use it in GitHub Desktop.
class Singleton
@get: -> @instance ?= new @
class Test extends Singleton
constructor: -> alert "Test constructed"
run: -> alert "Test run"
class OtherTest extends Singleton
constructor: -> alert "OtherTest constructed"
run: -> alert "OtherTest run"
Test.get().run()
OtherTest.get().run()
Test.get().run()
OtherTest.get().run()
@banacorn
Copy link

nice

@alpacaaa
Copy link

genius

@wlaurance
Copy link

Sweet, Thanks for this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment