Skip to content

Instantly share code, notes, and snippets.

@ta1kt0me
Last active December 20, 2017 02:51
Show Gist options
  • Select an option

  • Save ta1kt0me/d38165ec0f89178d5fd857e57eec67e9 to your computer and use it in GitHub Desktop.

Select an option

Save ta1kt0me/d38165ec0f89178d5fd857e57eec67e9 to your computer and use it in GitHub Desktop.
what is `this` in function in function
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