I'm not convinced this is useful JavaScript optimization advice. JavaScript doesn't have integers, and string literals are interned, so it shouldn't make a substantial difference if you have the same literal written out 15 times or just defined once and placed in a property. (In fact, using the plain literal everywhere may be faster because it omits the dynamic property access.)
Re:Andro.js
by jcromartie on Tuesday February 21, 2012 @10:04AM
(#3616667)
I'd rather mistype an identifier than a string literal, because nothing will complain about the wrong string literal.
Re:Andro.js
by maryrosecook on Tuesday February 21, 2012 @09:21AM
(#3616493)
Excellent point. I would normally do this, but I wanted to reduce the amount of indirection in the code as much as possible. But, it may still be worth doing so people aren't distracted by thinking "Wow, this girl should use constants".
Repeating strings is hard to refactor and comparing strings is much less efficient than comparing integers. Think about making sure every bit in two 2 * 8 * length string of bits plus overhead is the same vs two 32bit integers. The latter far fewer cycles.