I have read that .bind is used to preserve the value of 'this' and the function will be invoked in certain point of time in future where as for call/apply it will be invoked immediately. What could be some examples/scenarios where we call the functions in future(for bind) and bind 'this' value. Also, I would like to know the when to use which one - call, apply and bind.
Asked
Active
Viewed 42 times
0
-
1You have read this Q&A, right? [How to access the correct `this` inside a callback](/q/20279484/4642212). `.bind` is used to create a new function with a bound `this`; this function can serve as a callback, then. – Sebastian Simon Nov 01 '22 at 05:43
-
1There are no rules for "_when to use which one - call, apply and bind_", you're using one of those when you need its behavior. – Teemu Nov 01 '22 at 05:48
-
Oh, and `call` and `apply` aren’t much different from one another. `.call` can do what `.apply` does by using argument spread. I personally prefer always using `.call`, but I rarely need any of these three methods. – Sebastian Simon Nov 01 '22 at 05:51