Like most Javascript programmers, I have tended to follow
a simple rule for functions using 'this': eta-expand method
selections, use .bind, or get into trouble.

That is unnecessary, inefficient, and adds clutter.

The problem with rules-of-thumb is that most people only
have two of those;-) I agree that knowing and understanding all the relevant aspects is better, and reducing the number of details a programmer must worry about is a good language design goal. But when we can't communicate all the details, our rules have to be simple.
The rule above doesn't mention details, and doesn't discuss
alternatives, such as the DOM's EventListener interface, but it does cover your suggestions: if the function doesn't use 'this', there's no need to worry, and eta-expansion of method selections (only needed when not directly applied) ensures that method calls are always qualified.

   var short = function(..) { return obj.method(..); };

The problem with does-it-use-this is that it implies knowledge
about the function definition. Eta-expansion certainly adds clutter (but that is generic clutter which I'd like to get rid in the general case), but it works whether the function uses 'this' or not, and there is no reason for it to be inefficient.
But it doesn't really matter which rules we follow to work
around this hole, the issue is that the language spec leaves
this hole for programmers to fall into. Removing such sources of errors tends to be more useful than collecting extensive documentation about workarounds(*).

Claus

(*) Once, I used a modelling tool with extensive, carefully
   written and illustrated documentation. Using another
tool for the same application domain that didn't _need_ that kind of documentation was an interesting experience.

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to