繁体   English   中英

希望将coffeescript循环转换为javascript

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM