1) In the partial definition, is the arguments variable in the first line the same as the arguments variable in the last line? If not, what are the sources for each of those arguments objects?
No it's not. arguments
is based on the current function. In the first line it's the arguments supplied to partial
itself, in the third one it's the arguments applied to the function.
To quote the specification:
When control enters an execution context for function code, an arguments object is created
What we're doing here is applying the arguments supplied initially in addition to the ones supplied later on. We're concating the arguments given initially with the ones given during invocation to create a partial.
2) When the function call occurs on the final code line above, my understanding is that fixedArgs bound to [map] (that is, an array containing the map function). Then concat is called on it with the 2-dimensional array. Many problems, and not the correct answer, arise from these bindings, so they can't be the correct ones. How are the variables in partial bound when it's called?
What the code in the last line is doing is:
partial(map, square)
- creates a function out of map
that uses square
as the first argument, this basically creates a function that gets an array and squares it.
map(result, [[10, 100], [12, 16], [0, 1]])
- this performs a mapping again. This time we map every element in the array to the function declared above. The elements in the array are arrays themselves and the function we defined above takes an array and squares all its elements so what it does is square all the elements of the internal arrays.
So we get expect to get [100,1000],...