4 ms·
No. Bind creates a new function, call and apply do not.
by 29athrowaway 4y ago
No. Bind creates a new function, call and apply do not.
- osrec 4y agoMore specifically, bind creates a new function + context, that you can hold a reference to and reuse, but you cannot do this with call or apply.
- singlow 4y agoIn practice though, many places that used apply/call tend to bind instead.
- 29athrowaway 4y agoapply and call invoke a function with a specified receiver object, and arguments. bind creates a new function that is bound to a specified receiver.
- singlow 4y agoOne of the most common places front-end devs encountered call/apply was when binding functions to event handlers. In those cases an anonymous function was often generated which used apply or call. Bind replaces this dance for many cases. Hence, most cases where devs encountered js call/apply were replaced by bind. There are differences between the two, but they largely didn't matter for most cases.
- 29athrowaway 4y agoUnless you have strict performance requirements, then it does matter.