【问题标题】:How to write a require statement in coffeescript?如何在咖啡脚本中编写需求语句?
【发布时间】:2014-06-27 07:09:11
【问题描述】:

在 Gruntfiles 中,在 JS 版本中经常可以看到类似的内容。 我正在尝试用 Coffeescript 重写它。

require('load-grunt-config')(grunt);

你会如何在 CoffeeScript 中编写它?我什至不确定你会怎么称呼这样的东西。

【问题讨论】:

  • 好吧,require('load-grunt-config')(grunt) 有效,但我假设有更多的咖啡脚本-y 方式来做到这一点。

标签: coffeescript gruntjs


【解决方案1】:

最好写:

(require 'load-grunt-config') grunt

然后在example 中使用父级:

require('load-grunt-config') (grunt) #This is ok
require ('load-grunt-config')(grunt) #This is what you do not want

Coffescipt 是一种空格语法意义的语言。

【讨论】:

    【解决方案2】:

    你只需要一个函数然后立即执行它

    require('load-grunt-config')(grunt)
    

    require('load-grunt-config') grunt
    

    coffeescript 中的相同。

    【讨论】:

    猜你喜欢
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 2014-12-30
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 2014-06-04
    相关资源
    最近更新 更多