-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"do" for loop #2382
Comments
-1 for new syntax. I'm using array methods for this thing which resolves problems. [1, 2, 3, 4, 5].forEach (item, index) ->
console.log('hello', item, index) |
Not opposed to sytax further simplifying this, but you can already put it on one line, and it makes it explicit that there's a closure there. for item in [1, 2, 3, 4, 5] then do (item) ->
console.log item _ref = [1, 2, 3, 4, 5];
_fn = function(item) {
return console.log(item);
};
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
item = _ref[_i];
_fn(item);
} |
@connec Now that you point this out, I was mainly looking for a single line setup that gives me closure. Thanks for the Showing that it has closure with the function directly >> less syntax. |
I've search for |
I was not aware that this was already possible:
But I would like to propose a simplification, which would make the code nicer, and might align better with the original proposal. Simply remove the need for 'then' in this case:
And perhaps, this syntax would then implicitly pass on the for loop variables, e.g. this code in current notation:
Would become:
|
I find myself writing the coffee-script
do
function inside a lot offor
loops on the given item of the loop.Current setup:
I propose modifying the
for
setup to keep the nice syntax of the for loopBoth would still compile to the same functionality.
The text was updated successfully, but these errors were encountered: