Skip to content

Instantly share code, notes, and snippets.

@ritwickdey
Created November 2, 2017 12:37
Show Gist options
  • Save ritwickdey/48fc1073b81ac007c02137933a7f7c6e to your computer and use it in GitHub Desktop.
Save ritwickdey/48fc1073b81ac007c02137933a7f7c6e to your computer and use it in GitHub Desktop.
function fun1() {
setTimeout(function () { //normal
console.log("normal (setTimeOut)", this);
}, 0);
}
function fun2() {
setTimeout(() => { //arrow
console.log("arrow (setTimeOut)", this);
}, 0);
}
var ob = {
test1: () => console.log("arrow", this), // this => `window` --> it's okay...
test2: function () {
console.log("normal", this); // this => `ob` --> okay too...
},
test3: fun1, // this => `window` ---> Why????
test4: fun2, // this => `ob` ---> Why?? O_o;
}
ob.test1();
ob.test2();
ob.test3();
ob.test4();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment