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 M.Ahmed
Software Engineer
Call ( )
The call() method invokes a function with a
given this value and arguments provided
one by one.
Hafiz M.Ahmed
Software Engineer
Apply ( )
Apply: Invokes the function with a given this
value and allows you to pass in arguments
as an array.
Hafiz M.Ahmed
Software Engineer
Bind ( )
bind: returns a new function, allowing you
to pass any number of arguments.
Hafiz M.Ahmed
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 M.Ahmed
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 M.Ahmed
Software Engineer
Hafiz M.Ahmed
Did you find it useful?
Share your thoughts.