BTF is shorthand for "bound-this function expressions". BTFs are semantically equivalent to classic function expressions with the exception that "this" is lexically bound.
*Methodology * Using a modified version of the ES parser in UglifyJS, I generated an AST for the input string. I then traverse the AST, counting all occurrences of function expressions which do *not* contain a reference to "this" in its immediate scope. Of those function expressions, I count the number of functions whose first statement is a return statement, and of those, how many return an object literal in that return statement. The results so far can be viewed as a spreadsheet<https://docs.google.com/spreadsheet/ccc?key=0Aro5yQ2fa01xdENxUzBuNXczb21vUWVUX0tyVmNKTUE#gid=0> . The tool used for this analysis is available at http://www.khs4473.com/function-expr-count/. *Analysis * The total number of function expressions counted gives us a rough idea of how many function expressions could be converted to BTFs. In reality the number could be higher, since I'm not analyzing usage of Function.prototype.bind to achieve the same goal. For the surveyed code, the percentage of function expressions which do not reference "this" ranges between 31% and 87%. About half of all function expressions are suitable for conversion to BTFs. Clearly BTFs would offer immediate quantifiable benefit. Of the surveyed code, about 19% of BTF candidates contain a return statement as their first statement. This suggests that BTF syntax should be optimized for both "expression functions" and multi-statement function bodies, but with a preference given to multi-statement functions. Of the "expression functions", only 1.5% return an object literal. This suggests that BTF syntax should give preference to other forms, if there is a conflict. Thanks, kevin
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

