Last active
August 28, 2015 04:14
-
-
Save Jiert/605a11fa7fb5ac367e3c to your computer and use it in GitHub Desktop.
Code from an interview question about 'this'
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
var foo = { | |
a: function () { | |
console.log(this); | |
} | |
}; | |
foo.a(); | |
// => foo | |
foo['a'](); | |
// => foo | |
var someAsync = function (cb) { | |
cb(); | |
}; | |
someAsync(foo.a); | |
// => Window | |
setTimeout(foo.a, 0) | |
// => Window | |
someAsync(foo.a.bind(foo)); | |
// => foo | |
setTimeout(foo.a.bind(foo), 0); | |
// => foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment