node.js, need help to fix this bug "TypeError: object is not a function" -



node.js, need help to fix this bug "TypeError: object is not a function" -

i learning node.js. trying demos on cloud9. demo simple, 2 js files. checked line line, seems fine. please help me debug it.

resource.js file.

var util = require('util'); var eventemitter = require('events').eventemitter; function resource(m){ var maxevents = m; var self = this; process.nexttick(function(){ var count = 0; self.emit('start'); var t = setinterval(function(){ self.emit('data', ++count); if(count === maxevents){ self.emit('end', count); clearinterval(t); } }, 10); }); }; util.inherits(resource, eventemitter);

7-extemitter.js

var resource = require('./resource'); var r = new resource(7); r.on('start', function(){ console.log("i've started!"); }); r.on('data', function(d){ console.log(" received info -> " + d); }); r.on('end', function(t){ console.log("i'm done, " + t + " info events."); });

here's error message got:

code running @ 'http://node.myw714.c9.io'. important: utilize 'process.env.port' port , 'process.env.ip' host in scripts! /var/lib/stickshift/511e07b5500446f25c0001bd/app-root/data/407149/7-extemitter.js:4 var r = new resource(7); ^ typeerror: object not function @ object. (/var/lib/stickshift/511e07b5500446f25c0001bd/app-root/data/407149/7-extemitter.js:4:9) @ module._compile (module.js:449:26) @ object.module._extensions..js (module.js:467:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ module.runmain (module.js:492:10) @ process.startup.processnexttick.process._tickcallback (node.js:244:9)

you need remove initialization code.

var r = require('./resource'); r.on('start', function(){ console.log("i've started!"); }); r.on('data', function(d){ console.log(" received info -> " + d); }); r.on('end', function(t){ console.log("i'm done, " + t + " info events."); });

and add together line in resource.js, if want more general, should alter function construction allow set value m.

module.exports = new resource(7);

node.js

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -