In the following example I don't clearly understand why this.add
is not defined. I suspect that it is because the arrows function are executed immediately and at the moment of compilation and the add
function does not yet exist. Is this assumption correct? Or I'm missing something.
const arr= [1, 2, 3]
const squares = {
num: (arr) => {
return arr.map((x) => {
return (x * x) + this.add()
})
},
add: () => {
return 1
}
}
//TypeError: this.add is not a function
console.log(squares.num(arr))