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: you might want to use Reflect.apply instead.

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Function

prototype