2010/12/22 YANG Xudong <[email protected]>
>
> Fair point. Just to make my opinion clearer: all these conclusions are based
> on the assumption that compilers have become sufficiently smart, to the point
> where humans should care more about code
> readability/reusability/maintainability/etc. instead of optimization. In that
> specific case, a smart enough compiler could detect the array length change
> inside the loop and take relevant measures. Of course it might not be
> practical right now, but IMO that's the way to go in the future.
It is fairly hard to detect such a thing look at the following example:
var x = [0, 1, 2, 3], i;
function y(a) {
var l = a.length;
if (a.length < 10) {
a[l] = l;
}
return a;
};
for (i = 0; i < x.length; i++) {
y(x);
}
console.log(x); // Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
--
Poetro
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]