【问题标题】:How to use CoffeeScript's built-in helper functions?如何使用 CoffeeScript 的内置辅助函数?
【发布时间】:2012-03-26 08:13:13
【问题描述】:

CoffeeScript 带有一些 helper functions。如何使用它们?以flatten(Array) 为例。

【问题讨论】:

    标签: coffeescript


    【解决方案1】:

    这些函数似乎是供 CoffeeScript 编译器私人使用的。如果您想要这些功能,最好使用像 Underscore.js 这样的通用库。

    coffee> _ = require('underscore')
    coffee> _.flatten [1, 2, 3, [4, 5]]
    [ 1, 2, 3, 4, 5 ]
    

    【讨论】:

    • 没错。 helpers.coffee 的存在只是为了让 CoffeeScript 编译器不需要像 Underscore 这样的外部依赖。
    • 请注意,在coffee shell 中,_ 已经用​​作代表先前值的关键字。所以使用u = require('underscore')u.flatten [1,2,3,[4,5]]
    猜你喜欢
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 2022-01-08
    • 2011-08-24
    • 2011-04-13
    • 2019-07-10
    相关资源
    最近更新 更多