Skip to content

Instantly share code, notes, and snippets.

@kamiyam
Last active January 2, 2016 16:49
Show Gist options
  • Save kamiyam/8332542 to your computer and use it in GitHub Desktop.
Save kamiyam/8332542 to your computer and use it in GitHub Desktop.
Always the only instance
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