coffeescript 传递 require() 参数错误

coffeescript passing require() parameters wrong

代码 require ('./routes') app 编译为 require('./routes'(app)); 但我需要它编译为 require('./routes)(app)。我该怎么做?

括号在 CoffeeScript 中有两个用途:

  1. 他们将表达式分组:(a + b) * c
  2. 它们用于调用函数:f(x)

当你这样说时:

f (x)

关于 x 两边括号的含义有些歧义;他们是分组括号还是函数调用括号?如您所见,CoffeeScript 选择前者。

如果你想(或需要)使用圆括号来调用一个函数,你不希望在左圆括号之前有一个 space,你想要:

f(x)

在你的情况下你想要:

require('./routes') app

甚至:

require('./routes')(app)
(require './routes') app