Search code examples
node.jsinheritanceobservers

NodeJs Inheritance issue with node-observer


I have an issue when i'm trying to make an inheritance in NodeJS like this :

    var IObserver= require('node-observer');
    var Director=function(){
        Director.super_.call(this);
    }
    util.inherits(Director, IObserver);

And i'm getting this error :

util.js:634
  ctor.prototype = Object.create(superCtor.prototype, {
                          ^
TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (native)
    at Object.exports.inherits (util.js:634:27)
    at Object.<anonymous> (Director.js:17:6)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

I really don't know why I have this issue. I did it in other class and it works perfectly.

Someone else who can tell me how can I solve it ?

thanks in advance.


Solution

  • node-observer returns an instance of the Observer class. So to access the Class use IObserver.constructor:

    var IObserver= require('node-observer');
    var Director=function(){
        Director.super_.call(this);
    }
    util.inherits(Director, IObserver.constructor);