I am learning javascript via javascript.info.
I learned about bind
(and a lesson before about call
and apply
)
I see this post inquires about the differences on all 3.
After reading all that, I wonder: is there a scenario where using bind
would NOT cover the need for using either call
or apply
?
I mean, call
or apply
are meant for calling the function immediately. bind
- later on.
Would not the following work in all cases?
let f = function(){/* code here */};
let errorFreeF = f.bind(myContextObj);
errorFreeF();
A less verbose snippet:
function(){/* code here */}.bind(myContextObj)();
If the answer is using bind is always safe and indeed covers all scenarios, seems like the call/apply could be deprecated in future JS versions ? Or it performs worse?