简单循环的coffeescript [英] simple loop in coffeescript
本文介绍了简单循环的coffeescript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
I have this code:
count = $content.find('.post').length;
for x in [1...count]
/*
prev_el_height += $("#content .post:nth-child(" + x + ")").height();
*/
prev_el_height += $content.find(".post:nth-child(" + x + ")").height();
我预计这会变成
for (x = 1; x < count; x++) { prev_el ... }
,但它变为:
for (x = 1; 1 <= count ? x < count : x > count; 1 <= count ? x++ : x--) {
编辑:如何获得我的预期语法输出? p>
How do I get my expected syntax to output?
推荐答案
在CoffeeScript中,您需要使用关键字
的循环。在您的情况下:
In CoffeeScript, you need to use the by
keyword to specify the step of a loop. In your case:
for x in [1...count] by 1
...
这篇关于简单循环的coffeescript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文