The custom bind function implements any binding function call context

Why implement a custom bind function when you have apply and call?

  • Sum. Apply (null,…) sum. Apply (null,…) If it’s just once, it’s fine if you have it many times! Is not very annoying, why can’t we once in place; 2. Secondly, bind can be used to realize requirements while maintaining the original code style, which is more conducive to understanding the right and wrong; 3. Of course, there are other benefits, which I didn’t think of for the time being, the need to assemble business scenario descriptions. In short, specific scene specific analysis, the kind of convenient use of the kind of, and not a solid thing!

The above way found the problem

  • Since the above method is modified from the prototype, it can easily cause conflicts. Many third-party libraries implement similar methods, so to avoid conflicts, we decided to implement our own bind function as a method on our own namespace, similar to mynamespace.bind! But we here mainly about the realization of the function, so in order to explain the problem more simply, I used to write a global function to achieve!

Content to be continued….