I have object extends from event:
var A = function () {
EventEmitter.call(this);
};
inherits(A, EventEmitter);
var a = module.exports = Object.create(new A());
A.prototype.method = module.exports = function f(arg1,arg2){}
On another module I make:
var controller = require('./filename');
function main(){
controller.f(arg1,arg2);
}
I guess something with the require/export is wrong but I couldn't find what.
Try this:
var A = function() {
EventEmitter.call(this);
};
inherits(A, EventEmitter);
var a = module.exports = new A();
A.prototype.f = function(arg1, arg2) {
console.log("Hello, world!");
}
Your folly was to reassign module.exports
a second type. This should do what you want; namely, the export of the module is an instance of A
, such that require('./controller')
returns the A
instance, and you can call f(arg1, arg2)
on that.
By the way, the Object.create()
was extraneous.