Call , Apply , Bind in JavaScript

Vchanduu
3 min readJan 3, 2021

--

Let us take an object “name” which takes a method “printFullName”

suppose if we had one more object with firstname and lastname, if I want to print this full name again one method is to copy the above function and paste , but its not good way, that's where call method comes into picture.

Using call method we can do function borrowing.

Main application of function borrowing is we can borrow functions from other objects and use it with the data of some other objects.

First take the function which needs to be called , and in this call method first argument is reference (where keyword this needs to be pointed to)

In general case if we want to reuse them we don't keep functions inside this , we can take them off and keep it outside.

Suppose we want to add hometown

Suppose we had hometown and state

Apply Method :

The only difference between call and apply method is the way we pass arguments, we pass argument list as array.

Bind Method :

Bind method looks exactly same as call method, but only difference is instead of directly calling the method, the bind method binds this method printFullname with object and returns copy of that method.

The only diff between call and bind is , bind gives u the copy which can be invoked later rather than calling it directly.

--

--