Joined September 2014
·

pbihler

Leipzig
·
·

Posted to Singleton Pattern on Coffeescript over 1 year ago

What about this approach:

 class Singleton
  @getInstance: ->
    @_instance ?= new @(@,arguments...)

  constructor: (args...) ->
    unless @constructor ==  args.shift()
      throw new Error('Cannot call new on a Singleton')
    return args


class Manager extends Singleton
  constructor: ->
    [@arg] = super

It makes new Manager() unlikely.

Achievements
1 Karma
0 Total ProTip Views