0

I have this code in coffescript

copy pages.template  for pages in configFiles.pages

That generates this code in java script

var pages, _i, _len, _ref;

_ref = configFiles.pages(function() {});
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  pages = _ref[_i];
  copy(pages.template);
}

But what I want is to call 2 more functions inside the for like this:

var pages, _i, _len, _ref;

_ref = configFiles.pages(function() {});
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  pages = _ref[_i];
  copy(pages.template);
  copy2(pages.template);
  copy3(pages.template);
}

I don't know if this is a good practice or not. I am new in the programming world. If it is how can I do this in coffeescript ? If not what is the best solution ?

Thanks

3 Answers 3

3

Instead of nesting it in a comprehension, you can use block syntax for loops:

for pages in configFiles.pages
    copy(pages.template)
    copy1(pages.template)
    copy2(pages.template)
Sign up to request clarification or add additional context in comments.

Comments

1

Unrecommended, but it is technically possible to cram them into one line:

(copy pages.template; copy1 pages.template; copy2 pages.template) for pages in configFiles.pages

Comments

-1

In coffeescript you can nest list comprehensions/for loops. So you could do things like that.

(copy pages.template for pages in configFiles.pages for num in [3..1])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.