DEV Community

Cover image for #11) Explain call(), apply() & bind() ❓
Mayank Yadav
Mayank Yadav

Posted on

#11) Explain call(), apply() & bind() ❓

🔰call()

✔The call() method calls a function with a given this value and arguments provided individually.
call() method allows object to use method/function of another object.
call() accepts arguments.

image

🔰apply()

✔It is similar to call() method but call() method takes argument separately whereas in apply() method arguments are passed as an array.

image

🔰bind()

✔It creates a new function and when invoked has the this keyword set to the provided value.
image
✔In case of call() & apply() the function is immediately called but in case of _bind() it does not call in-fact it just return another function which you can call it later.
That's why in above example I've stored the value in a variable fun and then invoked it.


Top comments (0)