Skip to content

Instantly share code, notes, and snippets.

@sambostock
Last active August 15, 2016 05:28
Show Gist options
  • Save sambostock/b0e32bd263d647a6037f045b55daded8 to your computer and use it in GitHub Desktop.
Save sambostock/b0e32bd263d647a6037f045b55daded8 to your computer and use it in GitHub Desktop.
`this` is weird
let obj = {
fooFn: function() {
console.log('foofn: hi!');
},
barFn: function() {
console.log('barFn: calling fooFn');
this.fooFn();
console.log('barFn: called fooFn');
}
}
console.log('global: this will work fine:');
obj.barFn();
console.log('global: but this will break');
f = obj.barFn;
f();
console.log('wat');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment