Call, Apply and Bind in JavaScript

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Duncan McArdle

Duncan McArdle

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