JS: Function.prototype.call

By Xah Lee. Date: . Last updated: .
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:

JavaScript, Apply Function

BUY ΣJS JavaScript in Depth