2 ms·
If you wish you verify why is this, consider the following. Forget about String.prototype.trim at the moment. Consider this function: const f = function()
by partycoder 9y ago
If you wish you verify why is this, consider the following.
Forget about String.prototype.trim at the moment. Consider this function:
const f = function() { console.log('receiver is', this, '. arguments are', arguments) }
This function prints the receiver (aka "this"), and arguments.
If you use it in the following way:
['a', 'b', 'c'].map(Function.prototype.call, f)
The output is
receiver is [String: 'a'] . arguments are { '0': 0, '1': [ 'a', 'b', 'c' ] }
receiver is [String: 'b'] . arguments are { '0': 1, '1': [ 'a', 'b', 'c' ] }
receiver is [String: 'c'] . arguments are { '0': 2, '1': [ 'a', 'b', 'c' ] }
Meaning, that the receiver (aka "this") of the function will be the array element, and the arguments will be the array index and the array itself.