Best way to iterate over an array and call functions in coffeescript

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

Answers


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)

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

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])

Need Your Help

HTML 5 pattern not working for onclick event of button

html html5 validation

In a page, for getting field values I didn't use form tag, instead used Anchor tag's click event to get the values and used AJAX call to pass it to server.

how could i forbid a tableviewcell to be selected

iphone xcode uitableview

As usual, when a tableviewcell is touched, it will be selected. But now i need one cell in my tableview never be selected.how could i forbid a tableviewcell to be selected?