Last active
December 29, 2017 18:29
-
-
Save Storyyeller/c0044afa67cab098f652831d0ec43224 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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