I have a question,
// case 1
const stack = [];
[1,2,3].forEach(stack.push);
This will throw Error
Uncaught TypeError: Cannot convert undefined or null to object
at push (<anonymous>)
at Array.forEach (<anonymous>)
at <anonymous>:1:9
But this will be fine,
// case 2
const stack = [];
[1,2,3].forEach(element => stack.push(element));
console.log(stack); // [1,2,3]
And if you bind stack with this referring to itself,
// case 3
const stack = [];
[1,2,3].forEach(stack.push.bind(stack));
console.log(stack); // (9) [1, 0, Array(3), 2, 1, Array(3), 3, 2, Array(3)]
It also works in another way.
How can these happen? What is the difference between a method(case 1) and an arrow function(case 2)?