What do you need to do to get the following result? And why does it work?
> .concat[1,2,3] [ 1, 2, 3 ]
This expression looks very similar to:
But, actually, something completely different is going on:
First, the result of
.concat is computed. The result is the function stored in
Then the operand of the square bracket operator is evaluated. It consists of the comma operator (in this context, the comma is an operator, like
+) applied to three numbers:
> 1,2,3 3
'3' of the function returned by
.concat is accessed.
Normally, that produces
> .concat[1,2,3] undefined
If, however, you make the following assignment, you’ll get the result shown at the beginning:
> Array.prototype.concat = [1,2,3]; > .concat[1,2,3] [ 1, 2, 3 ]