While loop in CoffeeScript -
i'm new coffeescript , have been reading book, the little book on coffeescript. here few lines book's chapter 2 confused me while reading :
the low-level loop coffeescript exposes while loop. has similar behavior while loop in pure javascript, has added advantage returns array of results, i.e. array.prototype.map() function.
num = 6 minstrel = while num -= 1 num + " brave sir robin ran away"
though may coffeescript programmer, beingness newbie, i'm unable understand code does. moreover, words returns array of results doesn't seem go fact while loop construct, not function. notion of returning seems confusing. furthermore, variable num
string "brave sir robin ran away"
in every iteration of loop seems awkward, value num
beingness used loop counter.
i thankful if explain behavior of code , perhaps illustrate author trying convey simpler examples.
wow! didn't know absolutely makes sense if remember coffeescript returns lastly look of "block". in case returns (not via "return" statement if confuses you) expression
num + " brave sir robin ran away"
from block associated while status , homecoming multiple such expressions pushes them on array.
have on generated javascript , might clearer generated code pretty much procedural
var minstrel, num; num = 6; minstrel = (function() { var _results; _results = []; while (num -= 1) { _results.push(num + " brave sir robin ran away"); } homecoming _results; })();
i hope makes sense you.
coffeescript
No comments:
Post a Comment