Last active
December 20, 2017 02:51
-
-
Save ta1kt0me/d38165ec0f89178d5fd857e57eec67e9 to your computer and use it in GitHub Desktop.
what is `this` in function in function
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 A { | |
| constructor(value) { | |
| this.value = value | |
| } | |
| foo() { | |
| const fun = function() { console.log('fun: ', this) } | |
| fun(); | |
| const bindFun = function() { console.log('bindFun: ', this) }.bind(this) | |
| bindFun(); | |
| const arrowFun = () => { console.log('arrowFun: ', this) } | |
| arrowFun() | |
| } | |
| } | |
| new A("1").foo() | |
| // fun: undefined | |
| // bindFun: A { value: '1' } | |
| // arrowFun: A { value: '1' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment