Skip to the workspace
Pebellslearn by building
Using (this) keyword  ›  Lesson

Explicit Binding: call, apply and bind

Explicit Binding 12 min

javascript / Explicit Binding: call, apply and bind

Explore each scene at your own pace.

01 · Explicit Binding: call, apply and bind

Explicit Binding: call, apply and bind

Explicit Binding: call, apply and bind

call invokes an ordinary function with a receiver and positional arguments. apply uses an argument list. bind creates another function with a fixed receiver and optional leading arguments.

Calling now and preparing a callable for later are separate operations.

See the mechanism

Walk through the modelExplicit Binding: call, apply and bindAuthored snapshots of the example; use Run below to test the code.
receiverarticle
prefix"Read: "
Both forms invoke the function now with equivalent arguments.
1 of 3

Follow one example

javascript

call and apply run label immediately and return its result. bind does not run it; later is a function you can invoke afterwards. Bound ordinary-function receivers cannot be changed by another call receiver. These methods do not install a dynamic this binding into an arrow.

Predict, change and check

Predict: What is typeof later before you invoke it?

Test your explanation: Print typeof later, then call it twice. Replace article with a second record when creating a separate bound function and compare results.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Separate calling now from preparing a later call

call invokes a function now with an explicit receiver and positional arguments. apply invokes it now with an array-like argument list. bind returns a new function for a later call and can preset arguments as well as an ordinary function's receiver.

Borrowing a method does not copy its entire original object into the new receiver. The borrowed method must be compatible with the receiver's shape; some built-in methods require internal slots and are not generic. A constructor call through a bound ordinary function has additional this behavior, and lexical arrows still do not acquire a replaceable receiver.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.