Skip to content

Instantly share code, notes, and snippets.

@Jiert
Last active August 28, 2015 04:14
Show Gist options
  • Save Jiert/605a11fa7fb5ac367e3c to your computer and use it in GitHub Desktop.
Save Jiert/605a11fa7fb5ac367e3c to your computer and use it in GitHub Desktop.
Code from an interview question about 'this'
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