Skip to content

Instantly share code, notes, and snippets.

@fd
Forked from yvesvanbroekhoven/module-a-ext.js
Last active December 30, 2015 03:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fd/7766926 to your computer and use it in GitHub Desktop.
Save fd/7766926 to your computer and use it in GitHub Desktop.
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"
function ModuleA(name) {
this.name = name;
}
module.exports = ModuleA;
ModuleA.prototype.foo = function(){ return "foo"; };
ModuleA.prototype.getName = function(){ return this.name; };
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