Node.js参考错误:未定义类

时间:2016-09-13 05:06:56

标签: node.js

我正在编写一个导出一些函数的模块。我创建了一个调用模块的文件,但似乎无法获取文件来引用我在模块中创建的类。我不确定我做错了什么。这是代码。

 var EventEmitter = require('events').EventEmitter;
 var inherits = require('util').inherits;  

 var employeeEmitter = function(){}
 function employeeEmitter(data){
  EventEmitter.call(this);
 }           
 inherits(employeeEmitter, EventEmitter);   

 employeeEmitter.prototype.lookupByLastName = function(data, lastName)
 {var lName = _.where(data, {lastName: lastName});
 console.log(colors.red('Lookup By Last Name: ' + (lastName)));
 console.log(colors.blue('Event lookupByLastName raised! '+ lastName));
 console.log(lName); 
 };

 employeeEmitter.prototype.lookupById=function(data, id){
 console.log(colors.red('Lookup By ID: ' +id));
 console.log(colors.blue('Event lookupById'));   
 Id = _.findWhere(data, {id: id });
 console.log(Id);
 };

 module.export = employeeEmitter;   

这是我用来调用上述模块的文件

  var EmployeeEmitter = require('./employeeEmitter.js');
  data = [
  {id:1, firstName: 'John', lastName: 'Smith'},
  {id:2, firstName: 'Jane', lastName: 'Smith'},
  {id:3, firstName: 'John', lastName: 'Doe'}
   ];

  var EmployeeEmitter = new employeeEmitter(data);
  EmployeeEmitter.on('event1', function(data) {
  }); 


  EmployeeEmitter.lookupByLastName(data, 'Smith');
  EmployeeEmitter.addEmployee(data, 'William', 'Smith');
  EmployeeEmitter.lookupByLastName(data, 'Smith');
  EmployeeEmitter.lookupById(data, 2);

当我调用此文件时,我得到:引用错误employeeEmitter未定义

0 个答案:

没有答案