JavaScript: Function.prototype.call

By Xah Lee. Date: . Last updated: .
f.call(obj)
Call f with its this Binding having value of obj.
f.call(obj, arg1, arg2 etc)
Feed f with arguments arg1, arg2 etc.
// shows what f.call(arg) is doing

function ff() { return this; }

const obj = {};

console.log(
 ff.call(obj) === obj
); // true

Example with arguments.

function ff(a, b) { return a + b; }

console.log(
 ff.call(undefined, 3, 4) === 7
);
// true

Reflect.apply

Tip: better to use Reflect.apply

BUY
ΣJS
JavaScript in Depth

JS Obj Reference

Function

prototype