2015-08-13 12 views
2

我有,當我試圖在類似的NodeJS這一個繼承的問題:傳承的NodeJS問題與節點觀察者

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

而且我得到這個錯誤:

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) 

我真的不知道爲什麼我有這個問題。 我在其他課上做了,它完美的作品。

別人誰能告訴我我該如何解決?

在此先感謝。

+0

因爲'node-observer'的要求返回類的一個實例,而不是構造函數。 –

回答

3

node-observer返回Observer類的實例。所以要訪問該類使用IObserver.constructor

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

這是問題!謝謝 ! 我懷疑構造函數沒有正確傳遞。 –