Skip to content

Instantly share code, notes, and snippets.

@schamane
Created September 21, 2012 11:24
Show Gist options
  • Save schamane/3760957 to your computer and use it in GitHub Desktop.
Save schamane/3760957 to your computer and use it in GitHub Desktop.
Nodejs inheritance
/* main class */
var Adder = function(a, b){
this.a = a || 1;
this.b = b || 2;
};
Adder.prototype.add = function() {
return this.a + this.b;
};
/* class inheritance */
var Adder2 = function() {
Adder2.super_.apply(this, arguments);
this.b = 4;
};
require('util').inherits(Adder2, Adder);
/* usage */
var adder = new Adder2(5);
console.log(adder.add());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment