Skip to content

Instantly share code, notes, and snippets.

@Storyyeller
Last active December 29, 2017 18:29
Show Gist options
  • Save Storyyeller/c0044afa67cab098f652831d0ec43224 to your computer and use it in GitHub Desktop.
Save Storyyeller/c0044afa67cab098f652831d0ec43224 to your computer and use it in GitHub Desktop.
function Base() {}
Base.prototype.foo = function() {return 'foo in Base';};
Base.bar = function() {return 'bar in Base';};
function Child() {}
Object.setPrototypeOf(Child, Base);
Object.setPrototypeOf(Child.prototype, Base.prototype);
const homeCtor = Child;
const homeProto = Child.prototype;
Child.prototype.foo = function() {
// super.foo();
return Object.getPrototypeOf(homeProto).foo.call(this);
};
Child.bar = function() {
// super.bar();
return Object.getPrototypeOf(homeCtor).bar.call(this);
};
const obj = new Child;
console.log(obj.foo()); // foo in Base
console.log(Child.bar()); // bar in Base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment