Node.js Reference Error: Class is not defined -
i writing module exports few functions. created file calls module cant seem file reference class created in module. im not sure im doing wrong. here code.
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 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 id: ' +id)); console.log(colors.blue('event lookupbyid')); id = _.findwhere(data, {id: id }); console.log(id); }; module.export = employeeemitter;
this file using call above module
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);
when call file get: reference error employeeemitter not defined
Comments
Post a Comment