function.apply(context, argsArray) calls function in the given context, passing argsArray as the arguments for function.
In this case, function is [].splice
, which takes the following parameters, in this this order:
- index - at which to start changing the array
- howMany - elements to remove, starting at index
- element1,...,elementN - elements to insert into the array at index
[3,4].concat(_ref = [-3, -4, -5, -6])
evaluates to an array by concatenating the two arrays together, giving [3, 4, -3, -4, -5, -6]
. This is the argsArray passed to .apply()
, so that:
- index == 3 (start at index 3)
- howMany == 4 (remove 4 elements)
- element1,...,elementN == -3, -4, -5, -6 (the elements to insert at index 3, after removal)
Thus .apply()
is causing the .splice()
function to run in the context of the numbers
array, removing elements at indices 3, 4, 5 and 6, and then inserting the elements -3, -4, -5 and -6 between "2" and "7" in the original array.
Edit: See RobG's answer for a summary of what the original code is equivalent to (rather than an explanation of its parts).