Functions

call, apply & bind

Explicitly controlling what this refers to.

intermediate Experienced

These three methods let you set this explicitly when calling a function.

call and apply are "do it now with this receiver"; bind is "here is a pre-addressed envelope you can post later".

Key concepts

1
call invokes the function immediately with this and comma-separated arguments. apply is identical but takes arguments as an array. bind does not invoke — it returns a new function permanently bound to the given this.
callapplybindthis
2
bind is the classic fix for passing a method as a callback without losing its receiver, and it also enables partial application by pre-filling arguments.
bind