3 ms·
Why does everybody compare CoffeeScript against vanilla JavaScript? I find using underscore makes my code sufficiently elegant that I've never felt the need to
by bentlegen 13y ago
Why does everybody compare CoffeeScript against vanilla JavaScript? I find using underscore makes my code sufficiently elegant that I've never felt the need to switch to CoffeeScript.
- deleted 13y ago[deleted]
- krapp 13y agobentlegen is probably talking about http://underscorejs.org/ http://underscorejs.org/
- lucisferre 13y agoAh right, now I feel stupid.
- deleted 13y ago[deleted]
- sehrope 13y agoHe's talking about underscore.js which coincidentally was created by the same guy, Jeremy Ashkenas, that created CoffeeScript (and Backbone.js). Underscore actually is still useful with CS. You just don't need it as often as a lot of the list ops are built into the language.
- tlrobinson 13y agovar newArray = _.map(_.filter(array, function(item) { return item % 2; }), function(item) { return item + 1; }); vs newArray = (item + 1 for item in array when item % 2) Uh huh.
- oftenwrong 13y agoYou could also do it with chain, which could make the first example a bit simpler to read and write. It is something like: var newArray = _.chain(array).filter(function(item) { return item % 2; }).map(function(item) { return item + 1; }).value(); I often use CoffeeScript + Underscore
- deleted 13y ago[deleted]
- bentlegen 13y agoYou don't even need to call _.chain or value – underscore already does this automatically. You can also write it like so, if you like: var newArray = _(array).filter(function(item) { return item % 2; }).map(function(item) { return item + 1; }); Personally, I find this quite readable. And honestly, my comment was more about comparing CoffeeScript to its compiled JavaScript output, as is done in the slides. The compiled output is incredibly verbose and gives the false impression that JavaScript is always complicated.