Skip to content

Instantly share code, notes, and snippets.

@kkaefer
Created November 16, 2010 12:18
Show Gist options
  • Save kkaefer/701749 to your computer and use it in GitHub Desktop.
Save kkaefer/701749 to your computer and use it in GitHub Desktop.
var util = require('util');
function Parent(arg) {
console.log('parent constructor: arg=' + arg);
}
Parent.prototype.foo = function() {
console.log('fooing!');
return this;
};
function Child(arg) {
console.log('child constructor: arg=' + arg);
Child.super_.apply(this, arguments);
}
util.inherits(Child, Parent);
Child.prototype.foo = function() {
Child.super_.prototype.foo.apply(this, arguments);
console.log('child fooing!');
return this;
};
Child.prototype.bar = function() {
console.log('baring!');
return this;
};
new Child('baz').foo().bar();
// child constructor: arg=baz
// parent constructor: arg=baz
// fooing!
// child fooing!
// baring!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment