var x = []
var y = []
x.forEach (y.push)
Line 3 will throw Uncaught TypeError: Array.prototype.push called on null or undefined
if x is non-empty.
var x = [ 1 ]
var y = []
x.forEach (y.push)
Notes: x.forEach passes 3 arguments to y.push, 1 of which is y. Explicitly doing this does not cause an error.
y.push (1, 1, y)
Wrapping y.push inside an anonymous function will prevent the error, even if all arguments are passed through. As far as I can tell, it doesn't matter the number of arguments applied.
x.forEach (function (a, b, c, d, e, f, g, h, i, j) {
y.push (a, b, c, d, e, f, g, h, i, j)
})
Explicitly calling y.push with null and undefined will not cause the error, even when attempting to trick it with additional optional parameters.
y.push (1, 2, 3, undefined, 5, 6, null, 7, 8)