I am trying to achieve something like following in Node.js and Express.js, not able to find good examples of active this. Help appreciated.
base.js
--------
module.exports = {
baseFunction: function(){
.....
}
}
child.js
--------
module.exports = {
require('base'),
***** Some Magical Code ******
childFunction: function(){
.....
}
}
CallProgram.js
--------------
var child = require('child');
child.baseFunction();
How about this?
function extend(a, b) {
var result = Object.create(a);
for (var prop in b) {
if (b.hasOwnProperty(prop)) {
result[prop] = b[prop];
}
}
return result;
}
module.exports = extend(require('base'), {
***** Some Magical Code ******
childFunction: function(){
.....
}
});
The extend function will create a new object with a
as its prototype and will copy all properties of b
onto it.