Skip to content

Instantly share code, notes, and snippets.

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