JS: Function.prototype.call
f.call(thisBinding)
-
Call f with its this Binding having value of thisBinding.
// example of using Function.prototype.call function ff() { return this; } const jj = {}; console.log(ff.call(jj) === jj);
f.call(thisBinding, arg1, arg2, etc)
-
Feed f with arguments arg1, arg2, etc.
// example of using Function.prototype.call function ff(a, b) { this.x = a; this.y = b; } const jj = {}; ff.call(jj, 7, 8); console.log(jj.x === 7); console.log(jj.y === 8);
Examples of confusing form, commonly used before 2015 are:
Array.prototype.slice.call(ArrayLikeObject)
see Array-Like Object to ArrayArray.prototype.forEach.call(ArrayLikeObject, arrayMethod)
see Apply Array Method to Array-Like Object