-
Couldn't load subscription status.
- Fork 2k
Description
currently, if i have lots of no return functions, i need manually add an empty line 'return' to force coffee not compile return line to javascript code.
testFunc = ->
for i in [1..5]
execSomething i
return
with empty return, the js code looks good
testFunc = function() {
var i, j;
for (i = j = 1; j <= 5; i = ++j) {
execSomething(i);
}
};
but if i dont add 'empty return' at the end of func
testFunc = ->
for i in [1..5]
execSomething i
it will create a 'results' object, it is waste, and the code looks no i wanted.
Also when some callback func nested, if no 'empty return', lots of 'results' object, much horrible.
testFunc = function() {
var i, j, results;
results = [];
for (i = j = 1; j <= 5; i = ++j) {
results.push(execSomething(i));
}
return results;
};
In livescript, i can create no return function by simplely define a function with !-> that means no return value; -> just like coffeescript, auto return the last variable
(webstrom livescript plugin can't highlight code, so i try to use coffee, it's plugin work much better )
the !-> works just i wanted:
testFunc = !->
for i in [1..5]
execSomething i
compile to
testFunc = function() {
var i, j;
for (i = j = 1; j <= 5; i = ++j) {
execSomething(i);
}
};
especially, in nodejs, have lots of nested callback functions, 99% of them are no return function, !-> can solve this problem.