Created
June 2, 2019 16:19
-
-
Save aleph-naught2tog/7175ddeda82fa0dd871427056c3d8fe6 to your computer and use it in GitHub Desktop.
super
This file contains hidden or 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 SuperClass { | |
nonarrow() { | |
console.log('nonarrow', 'superclass'); | |
} | |
arrow = () => { | |
console.log('arrow', 'superclass'); | |
} | |
} | |
class SubClass extends SuperClass { | |
nonarrow() { | |
super.nonarrow(); | |
console.log('nonarrow', 'subclass') | |
} | |
/* | |
super.arrow(); | |
^ | |
TypeError: (intermediate value).arrow is not a function | |
*/ | |
arrow = () => { | |
super.arrow(); | |
console.log('arrow', 'subclass'); | |
} | |
} | |
const superInstance = new SuperClass(); | |
const subInstance = new SubClass(); | |
console.group('--- superclass calls first ---'); | |
superInstance.nonarrow(); | |
superInstance.arrow(); | |
console.groupEnd(); | |
console.group('--- now the subclass calls. ---'); | |
subInstance.nonarrow(); | |
subInstance.arrow(); | |
console.groupEnd(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment