Classical inheritance for constructors.
<script src="inherit.js"></script>
npm install https://gist.github.com/abernier/decf360c677a54aa415c/download
var inherit = require('inherit');
function A() {}
A.prototype.foo = function () {};
function B() {
B.uber.constructor.apply(this, arguments);
}
inherit(B, A);
B.prototype.foo = function () {
this.constructor.uber.foo.apply(this, arguments);
}
NB:
B.uber
references to A.prototype
constructor
property.xxxxxxxxxx
<html class="no-js">
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,initial-scale=1,user-scalable=no">
</head>
<body>
<script src="inherit.js"></script>
<script style="display:block; white-space:pre; font-family:monospace;">
var inherit = this.inherit || require('inherit');
function Animal(name) {
this.name = name;
}
Animal.prototype.move = function (meters) {
alert(this.name + ' moved ' + meters);
}
function Snake() {
Snake.uber.constructor.apply(this, arguments); // borrow parent's constructor
}
inherit(Snake, Animal); // Snake.uber = Animal.prototype
Snake.prototype.move = function () {
alert('Slithering...');
this.constructor.uber.move.call(this, 5); // borrow parent's move method
}
var kaa = new Snake('Kaa');
kaa.move();
</script>
</body>
</html>