Created
September 21, 2012 11:24
-
-
Save schamane/3760957 to your computer and use it in GitHub Desktop.
Nodejs 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
/* 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