Skip to content

Instantly share code, notes, and snippets.

@allenluce
Created November 12, 2015 19:12
Show Gist options
  • Save allenluce/9e4208fae5644f3ca77a to your computer and use it in GitHub Desktop.
Save allenluce/9e4208fae5644f3ca77a to your computer and use it in GitHub Desktop.
One way of cross-module node.js inheritance
module.exports = function() {
console.log("In base constructor.");
}
module.exports.prototype.myfunc = function() {
console.log("This is the base.");
}
var base = require ('./base');
var util = require('util');
function SubClass() {
console.log("In sub constructor.");
SubClass.super_.apply(this, arguments);
}
util.inherits(SubClass, base);
SubClass.prototype.myfunc = function() {
console.log("This is the sub.");
SubClass.super_.prototype.myfunc.apply(this, arguments);
}
var obj = new SubClass();
obj.myfunc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment