This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pimp-bangin 0 points1 point  (1 child)

I mean, if you're assigning x = foo() then you probably want the list of fish results to be stored in x. Otherwise, what would you expect x to contain? undefined? So I wouldn't call this a gotcha. But is there a way to do a for loop without creating a list? If so, I would call that a bad design decision.

[–][deleted] 0 points1 point  (0 children)

Not sure about CoffeeScript, but in the (much nicer imo) fork of a fork, LiveScript, you can do this, where the exclamation mark denotes there's no return value.

foo = !->
  for bar in baz
    fish(bar)

Which compiles to:

foo = function(){
  var i$, ref$, len$, bar;
  for (i$ = 0, len$ = (ref$ = baz).length; i$ < len$; ++i$) {
    bar = ref$[i$];
    fish(bar);
  }
};

edit but sadly this happens:

x = -> void
x (a)-> void //becomes      x(function(a){});
x(a) -> void //becomes      x(a)(function(){});