Call, Apply and Bind in JavaScript

Given the various ways in which the infamous this keyword can be altered in JavaScript (global, functions, arrow functions, classes, objects, etc.) it’s not surprising that somewhere along the way functionality started appearing that helps alter the calling context, and thus the value of this . Three particular functions that have appeared to help are Call, Apply and Bind, and there’s a reason that I list them in that order.

Call

Think of Call as being like saying “I’d like to call something, but I’d like to provide my own context for where it gets called”. This makes a lot of sense when you look at objects and classes. Take the following example:

Apply

Think of Apply as being like Call, but with the ability to supply parameters to the target function as an array rather than standard parameters. Otherwise, it’s more or less identical:

Bind

Think of Bind as being like a re-usable version of Call. You declare a variable, and then bind it to the target function, with an optional target context, and provide some optional parameters, and then you can call it whenever you want.

Full-stack software developer from the UK, author of the Aftermath book series, full time tech-nerd.