I'm having a problems properly defining inheritance in my app when my parent class has dependencies that I don't specify again for my child class.
Here is my setup:
parent.js
var foo = require('foo');
function Parent() {};
Parent.prototype.getFoo = function() {
return foo;
};
module.exports = Parent;
child.js
var util = require('util');
var Parent = require('./parent');
function Child() {
Parent.call(this);
}
util.inherits(Child, Parent);
module.exports = Child;
In my app, if I call child.getFoo()
, it will return undefined
unless I declare var foo = require('foo')
in the Child
class.
Is there a way to avoid this kind of redundancy? I'd like to set up dependencies only once in the parent class and avoid having to copy paste code to any other classes that inherit from it.