Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Example with Normal Function
// Value of "this" in this method is overridden to 3
function foo() {
return function (value) {
console.log(this.value) // 3
}
}
var obj1 = {
value: 2
}
var obj2 = {
value: 3
}
var bar = foo.call(obj1)
bar.call(obj2)
// But if we use arrow function then value of "this" will not overide
// Example with arrow function
function foo() {
return (value) => {
console.log(this.value) //2
}
}
var obj1 = {
value: 2
}
var obj2 = {
value: 3
}
var bar = foo.call(obj1)
bar.call(obj2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.