-
Couldn't load subscription status.
- Fork 2k
Closed
Description
Hello guys! Thank you for creating and supporting CoffeeScript!
Often when I want to extract loop to separate method I write like this:
performEach = ->
el.perform() for el in collectionBut always getting loop which collects returned data from el.perform():
var performEach;
performEach = function() {
var el, i, len, results;
results = [];
for (i = 0, len = collection.length; i < len; i++) {
el = collection[i];
results.push(el.perform());
}
return results;
};Then I add explicit return statement:
performEach = ->
el.perform() for el in collection; returnAnd getting what I want:
var performEach;
performEach = function() {
var el, i, len;
for (i = 0, len = collection.length; i < len; i++) {
el = collection[i];
el.perform();
}
};Proposal! What do you think about returnless arrow? Something like this:
performEach = |> # Note new syntax: "|>". Fat arrow syntax: "||>"
el.perform() for el in collectionCompiles to:
var performEach;
performEach = function() {
var el, i, len;
for (i = 0, len = collection.length; i < len; i++) {
el = collection[i];
el.perform();
}
};For many APIs is it important what value was returned (for example it is event handlers in jQuery).
Also there is article about it http://programmaticallyspeaking.com/why-i-hate-implicit-return-in-coffeescript.html
Metadata
Metadata
Assignees
Labels
No labels