3 ms·
Is there any reason the object comprehensions can't be rewritten from: ages = (function() { __a = []; __b = years_old; for (child in __b) {
by grayrest 17y ago
Is there any reason the object comprehensions can't be rewritten from:
ages = (function() {
__a = []; __b = years_old;
for (child in __b) {
age = __b[child];
if (__hasProp.call(__b, child)) {
__a.push(child + " is " + age);
}
}
return __a;
}).call(this);
to:
ages = (function() {
__a = []; __b = years_old;
for (child in __b) if (__hasProp.call(__b, child)) {
age = __b[child];
__a.push(child + " is " + age);
}
return __a;
}).call(this);
It's fairly minor but saves a few assignments and generates slightly less noise.
- jashkenas 17y agoThanks, grayrest. That's a nice improvement that has the lovely side effect of simplifying the code generation needed to implement comprehensions. I've pushed a patch that implements your suggestion, and all the tests are passing: http://github.com/jashkenas/coffee-script/commit/7667e16732268944232d31cea6a201698ce0661a#diff-5 http://github.com/jashkenas/coffee-script/commit/7667e167322... Thanks for that.