Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Thanks, 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/7667e167322...

Thanks for that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: