javascript bind vs apply/call

When you want that function to later be called with a certain context, useful in events. Call/apply call the function immediately, whereas bind returns a function that when later executed will have the correct context set for calling the original function. This way you can maintain context in async callbacks, and events. I do this a lot:…

javascript apply, call and constuctor

Let’s first create a simple function that we will be using through the rest of this post. This function will just return an array with the current value ofthis and the two supplied arguments. <script type=“text/javascript”> function makeArray(arg1, arg2){     return [ this, arg1, arg2 ]; } </script> Most common way, unfortunately, global function calls When we are learning JavaScript we learn how to define…