Yes, it is. The "unique" utility of call
is to pass this to force an execution context followed by arguments.
I would like to respond more fully, but there is not much else to say I believe:)
By your description you understand the utility, but an example is an old gambiarra to convert collections of elements that come from for example document.getElementsByTagName
, or document.querySelectorAll
in an array:
var elementos = [].slice.call(colecao);
What this does is call the .slice
method of this array by passing it colecao
to this
, which causes JavaScript to treat colecao
as an array and copy it.
Similar to .call
is .apply
that does the same but instead of passing arguments after this
one by one, we can pass an array:
function log(teste, a, b, c) {
console.log(this, teste, a, b, c);
}
log.call({
metodo: 'call'
}, 'testeA', 1, 2, 3);
log.apply({
metodo: 'apply'
}, ['testeB', 1, 2, 3]);
// e depois há maneiras mais modernas :)
var arr = [1, 2, 3, 4];
log.apply({metodo: 'apply destructured'}, ['testeC', ...arr]);