Skip to content

Instantly share code, notes, and snippets.

@AkashRajvanshi
Last active September 26, 2019 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkashRajvanshi/1f141d4ec786bb868610699ab0bd89a0 to your computer and use it in GitHub Desktop.
Save AkashRajvanshi/1f141d4ec786bb868610699ab0bd89a0 to your computer and use it in GitHub Desktop.
// 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