How To Access Argument Object Inside Arrow Function
The arguments Object inside listOfArg function refers to parent arguments with arrow function. And without arrow function this key reference would change and listOfArg function wil
Solution 1:
From MDN Docs
An arrow function does not have its own this; the this value of the enclosing execution context is used.
If you use
listOfArg = () => {
console.log(arguments)
}
this
inside onScrollEvent
would refer to the component this
and you would get arguments passed to the component because arrow function would use enclosing execution context which is the React Component.
Now, if you do not use arrow function:
listOfArg() {
console.log(arguments)
}
Here, listOfArg
will have its own this
and would print arguments it was called with: ["1", "2", ...]
which is expected.
Post a Comment for "How To Access Argument Object Inside Arrow Function"