I have two modules: apirequest.js and feed.js. When I call feed.start()
in apirequest, I get, TypeError: Object #<Feed> has no method 'start'
. Why is this? Doesn't util.inherits(Feed, APIRequest);
inherit APIRequest's properties?
apirequest.js
var EventEmitter = require('events').EventEmitter;
var util = require('util');
function APIRequest(endpoint) { }
APIRequest.prototype.start = function() { }
util.inherits(APIRequest, EventEmitter);
module.exports = APIRequest;
feed.js
var util = require('util');
var APIRequest = require('../lib/api_request');
function Feed(endpoint) {
APIRequest.call(this, endpoint);
}
util.inherits(Feed, APIRequest);
var feed = new Feed(endpoint);
feed.start();
I have two modules: apirequest.js and feed.js. When I call feed.start()
in apirequest, I get, TypeError: Object #<Feed> has no method 'start'
. Why is this? Doesn't util.inherits(Feed, APIRequest);
inherit APIRequest's properties?
apirequest.js
var EventEmitter = require('events').EventEmitter;
var util = require('util');
function APIRequest(endpoint) { }
APIRequest.prototype.start = function() { }
util.inherits(APIRequest, EventEmitter);
module.exports = APIRequest;
feed.js
var util = require('util');
var APIRequest = require('../lib/api_request');
function Feed(endpoint) {
APIRequest.call(this, endpoint);
}
util.inherits(Feed, APIRequest);
var feed = new Feed(endpoint);
feed.start();
Share
Improve this question
asked Mar 19, 2013 at 6:55
kenneth koontzkenneth koontz
8691 gold badge9 silver badges16 bronze badges
1 Answer
Reset to default 13The problem is order:
APIRequest.prototype.start = function() { }
util.inherits(APIRequest, EventEmitter); <-- *overwrites* APIRequest.prototype
If you swap those lines, it'll work:
util.inherits(APIRequest, EventEmitter);
APIRequest.prototype.start = function() { }