Skip to content

Instantly share code, notes, and snippets.

@chrislaughlin
Last active January 2, 2017 21:45
Show Gist options
  • Save chrislaughlin/08bae111b07b529b35f1c67a42771604 to your computer and use it in GitHub Desktop.
Save chrislaughlin/08bae111b07b529b35f1c67a42771604 to your computer and use it in GitHub Desktop.
"this" mistakes
this.foo = 'foo';
document.querySelector('.my-div').onclick = function() {
console.log(this.foo)
}
//Logs undefined
document.querySelector('.my-div').onclick = function() {
console.log(this.foo)
}.bind(thid);
//Logs 'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment