3 ms·
It's premature optimization. The extra time taken for a scope lookup is completely insignificant compared to the network costs in loading the script. Perhaps i
by mhansen 15y ago
It's premature optimization. The extra time taken for a scope lookup is completely insignificant compared to the network costs in loading the script.
Perhaps if this was inside a tight inner loop, I could understand, but here it's completely unneccessary.
- jarin 15y agoSure, but what's the drawback? I think very simple premature optimizations are just fine, especially when someone else does them for me.
- wladimir 15y agoIt looks like the kind of optimization that a compiler could do pretty trivially, and you shouldn't have to be concerned about as a human, as it makes the code less readable. Then again, Javascript is a strange animal here as the code is provided to the execution environment as plaintext instead of bytecode/assembly. I guess a JS-to-JS compiler such as closure could handle it.
- thezilch 15y agoIs it premature or unnecessary, if the methodology comes natural? Why not get into the habit of reading and writing Javascript with optimization naturally ingrained into the first pass? The optimization(s) may not be immediately necessary here, but there's no harm in practicing these patterns in all facets of language use, unless we want to have a separate conversation whether the patterns are detrimental to syntax.