3

应用程序.js

var Website = new require( './jslib/website.js' );

./jslib/website.js

var util = require('util'),
    events = require('events');

module.exports = Website;
function Website()
{
    events.EventEmitter.call( this );
    return this;
}
util.inherits( Website, events.EventEmiter );

控制台输出

PATH_TO_APPDIR>node app.js

util.js:538
  ctor.prototype = Object.create(superCtor.prototype, {
                                          ^
TypeError: Cannot read property 'prototype' of undefined
    at Object.exports.inherits (util.js:538:43)
    at Object.<anonymous> (PATH_TO_APPDIR\jslib\website.js:9:6)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at new require (module.js:378:17)
    at Object.<anonymous> (PATH_TO_APPDIR\app.js:1:16)
    at Module._compile (module.js:449:26)

这是 Windows 7 上的 NodeJS 8.22 *

4

1 回答 1

9

您的代码中有错字。

util.inherits( Website, events.EventEmiter );

应该

util.inherits( Website, events.EventEmitter );
于 2013-03-12T06:36:24.803 回答