I created a singleton class that I want to extend. It (half) works in that it creates only one instance of the class, but the properties added to the subclass are undefined. Here is the original singleton:
class Singleton _instance = undefined @getInstance: -> if _instance is undefined console.log 'no instance exists, so create one' _instance = new _Singleton() else console.log 'an instance already exists.' class _Singleton constructor: -> console.log 'new singelton' module.exports = Singleton
And here is the subclass:
Singleton = require('./singleton') class Stinky extends Singleton constructor: -> var1 : 'var1' module.exports = Stinky
Now, if I use the following in my node application:
Stinky = require './stinky' thing1 = Stinky.getInstance() thing2 = Stinky.getInstance() console.log "Thing var1: #{thing1.var1}"
The getInstance () method behaves as expected, but var1 is undefined. If I do the same on non-singleton classes, they work fine. Thanks.
source share