0% found this document useful (0 votes)
56 views8 pages

JavaScript Call, Apply, Bind Guide

Call and apply allow you to control the value of this in a function and execute the function immediately, with call accepting arguments as a comma separated list and apply accepting arguments in an array. Bind returns a new function with this set to the first parameter passed to bind but does not execute the function immediately.

Uploaded by

HIMANSHI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views8 pages

JavaScript Call, Apply, Bind Guide

Call and apply allow you to control the value of this in a function and execute the function immediately, with call accepting arguments as a comma separated list and apply accepting arguments in an array. Bind returns a new function with this set to the first parameter passed to bind but does not execute the function immediately.

Uploaded by

HIMANSHI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript

Call(), Apply() &


Bind()

Let’s Uncover it
Concept

call, bind, and apply are essential


JavaScript methods that allow you to
control the value of this in a function. This
can be incredibly useful in various
scenarios, especially when working with
objects or constructors.

Hafiz [Link]
Software Engineer
Call ( )
The call() method invokes a function with a
given this value and arguments provided
one by one.

Hafiz [Link]
Software Engineer
Apply ( )
Apply: Invokes the function with a given this
value and allows you to pass in arguments
as an array.

Hafiz [Link]
Software Engineer
Bind ( )
bind: returns a new function, allowing you
to pass any number of arguments.

Hafiz [Link]
Software Engineer
Summary

Call and apply are pretty interchangeable.


Both execute the current function
immediately. You need to decide whether
it’s easier to send in an array or a comma
separated list of arguments. You can
remember by treating Call is for comma
(separated list) and Apply is for Array.

Whereas Bind creates a new function that


will have this set to the first parameter
passed to bind().

Hafiz [Link]
Software Engineer
Summary

Call and apply are pretty interchangeable.


Both execute the current function
immediately. You need to decide whether
it’s easier to send in an array or a comma
separated list of arguments. You can
remember by treating Call is for comma
(separated list) and Apply is for Array.

Whereas Bind creates a new function that


will have this set to the first parameter
passed to bind().

Hafiz [Link]
Software Engineer
Hafiz [Link]

Did you find it useful?


Share your thoughts.

You might also like