I have an arrow function that I am trying to execute with call()
. For the sake of simplification, as follows:
Operational as expected
const func = (e) => {
console.log(e)
}
func.call(null, e)
Hmm ... what's going on here?
I would expect the following code to pass element
into func
as this
.
const func = (e) => {
console.log(this)
console.log(e)
}
func.call(element, e)
But, instead this
remains undefined
.
If I switch it to a regular function definition, all works as expected.
const func = function (e) {
console.log(this)
console.log(e)
}
func.call(element, e)
Question
Why am I not able to pass a context for this
into an arrow function from call()
?