In JavaScript, binding is always explicit, and can easily be lost, so a method using this will not refer to the proper object in all situations, unless you force it to. Overall, binding in JavaScript is not a difficult concept, but it is far too often ignored or glossed over by JavaScripters, which leads to confusion.That being said, you may need to already be comfortable with first-class functions to totally grok it.
Also, I was somewhat disappointed by the statement:
Such a closure will be maintained by the JavaScript runtime no matter what, so there is no extra cost to using it. Even if there were, I’m fairly confident that it would be far less than the cost of an extra function call at every turn of the loop.I’m poking around now to see if I can find real performance numbers for bind() vs. lexically binding this. The words “fairly confident” are a giant red flag in any optimization discussion.
.jpg)
0 comments:
Post a Comment