I saw this snippet in Ember.js:
for (var i=0, l=deps.length; i<l; i++) {
if (deps[i] === 'exports') {
reified.push(exports = {});
} else {
reified.push(requireModule(resolve(deps[i])));
}
}
Please take a look at var i=0, l=deps.length; i<l; i++
, the length of deps
is defined before the loop. I was wonder why did they have to do that instead of just use var i=0; i<deps.length; i++
. I think maybe this is a "performance trick", so I decided to make a test on jsperf:
http://jsperf.com/predefined-length-vs-inline-defined-length
The result shows that the second one is faster. So there is must be another reason they used the first one.
Anyone have any idea? Thanks a lot.