> Articles > call(), apply() and bind() in JavaScript
In this article, we will explain call(), apply() and bind() methods in JavaScript.
A function is an object and every function has methods call(), apply and bind() in JavaScript. These methods are used to set the value of this. They are very useful to use this appropriately and in many other scenarios like Function Borrowing, Function Currying. Let's see the call(), apply() and bind() methods in JavaScript in detail with examples.
call() method in JavaScript is used to invoke the function, it will pass an object as first parameter which will be the value of this inside function.
Syntax
functionName.call(objectName);
functionName.call(objectName, param1, param2,...);
apply() method in JavaScript is same as call(). It is used to invoke the function but the parameters will be passed in array. This may be very useful in scenarios where we get the input in form of array or we have to pass variable number of arguments.
Syntax
functionName.apply(objectName);
functionName.apply(objectName, [param1, param2,...]);
bind() method in JavaScript is used to create new function, it will pass an object as parameter which will be the value of this inside function.
Syntaxvar bFunction = functionName.bind(objectName);
Implementation