Last active
August 15, 2016 05:28
-
-
Save sambostock/b0e32bd263d647a6037f045b55daded8 to your computer and use it in GitHub Desktop.
`this` is weird
This file contains 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
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