![](/img/trans.png)
[英]How do I convert a JavaScript forEach loop/function to CoffeeScript
[英]Looking to convert a coffeescript loop to javascript
我希望将其转换为javascript,尽管我不太会阅读coffeescript。 它看起来像一个while循环,但确实不确定。
for foo, i in foos when not x? or x > y
我使用的最简单的方法是coffeescript.org 。 单击“尝试CoffeeScript”选项卡,将您的CoffeeScript粘贴在左侧,等效的JavaScript显示在右侧。
您的示例是一个for循环。 CoffeeScript使用while
关键字进行while循环, until
for while not循环。 那么for foo, i in foos when not x? or x > y
for foo, i in foos when not x? or x > y
JavaScript中的for foo, i in foos when not x? or x > y
看起来像这样:
var foo, i, _i, _len;
for (i = _i = 0, _len = foos.length; _i < _len; i = ++_i) {
foo = foos[i];
if ((typeof x === "undefined" || x === null) || x > y) {
alert("Hello CoffeeScript!");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.