Created
September 10, 2016 21:43
-
-
Save moshest/c4ee18366b233128fe6fc7f3ebb43dff to your computer and use it in GitHub Desktop.
ES6 methods implementation
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
class Foo { | |
test() { | |
return 'Foo'; | |
} | |
} | |
class Bar extends Foo { | |
test() { | |
return `${super.test()}Bar`; | |
} | |
} | |
class FooX { | |
test() { | |
return 'FooX'; | |
} | |
} | |
class BarX extends FooX { | |
test() { | |
return `${super.test()}Bar`; | |
} | |
} | |
const bar = new Bar(); | |
// The same signature but different behavior | |
console.log(Bar.prototype.test.toString() === BarX.prototype.test.toString()); // true | |
console.log(Bar.prototype.test.call(bar)); // "FooBar" | |
console.log(BarX.prototype.test.call(bar)); // "FooXBar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment