Skip to content

Instantly share code, notes, and snippets.

@Storyyeller
Created December 28, 2017 05:40
Show Gist options
  • Save Storyyeller/30540709bfa836d8161b81df3e0e7d89 to your computer and use it in GitHub Desktop.
Save Storyyeller/30540709bfa836d8161b81df3e0e7d89 to your computer and use it in GitHub Desktop.
function Base() {}
Base.prototype.foo = function() {return 'foo in Base';};
Base.prototype.bar = function() {return 'bar in Base';};
function Child() {}
Object.setPrototypeOf(Child, Base);
Object.setPrototypeOf(Child.prototype, Base.prototype);
Child.prototype.foo = function() {return 'foo in Child';};
Child.prototype.whiz = function() {return 'whiz in Child';};
var b = new Base;
var c = new Child;
console.log(b.foo()); // foo in Base
console.log(b.bar()); // bar in Base
console.log(c.foo()); // foo in Child
console.log(c.bar()); // bar in Base
console.log(c.whiz()); // whiz in Child
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment