Created
November 12, 2015 19:12
-
-
Save allenluce/9e4208fae5644f3ca77a to your computer and use it in GitHub Desktop.
One way of cross-module node.js inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function() { | |
console.log("In base constructor."); | |
} | |
module.exports.prototype.myfunc = function() { | |
console.log("This is the base."); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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