-
-
Save fd/7766926 to your computer and use it in GitHub Desktop.
This file contains 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 ModuleA = require('module-a'); | |
var ModuleB = require('module-b'); | |
var A = new ModuleA("A"), | |
B = new ModuleB("B"); | |
A.foo() // => "foo" | |
A.bar() // => [error] | |
A.getName() // => "A" | |
B.foo() // => "foo" | |
B.bar() // => "bar" | |
A.getName() // => "Sir B" |
This file contains 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
function ModuleA(name) { | |
this.name = name; | |
} | |
module.exports = ModuleA; | |
ModuleA.prototype.foo = function(){ return "foo"; }; | |
ModuleA.prototype.getName = function(){ return this.name; }; |
This file contains 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 ModuleA = require('module-a'); | |
function ModuleB(name) { | |
ModuleA.call(this, name); | |
} | |
module.exports = ModuleB; | |
ModuleB.prototype = new ModuleA(); | |
ModuleB.prototype.constructor = ModuleB; | |
ModuleB.prototype.bar = function(){ return "bar"; }; | |
ModuleA.prototype.getName = function(){ return "Sir " + ModuleA.prototype.getName.call(this); }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment