Javascript CoffeeScript编译:如果
我正在为API编写一些CoffeeScript代码,在代码的错误捕获部分,我放置了一个IF语句。现在,在编译过程中,CoffeeScript表示IF语句是意外的Javascript CoffeeScript编译:如果,javascript,coffeescript,Javascript,Coffeescript,我正在为API编写一些CoffeeScript代码,在代码的错误捕获部分,我放置了一个IF语句。现在,在编译过程中,CoffeeScript表示IF语句是意外的 # Handle Errors app.error (err, req, res, next) -> if err instanceof NotFound res.send '404, not found.' else res.send '500, internal server
# Handle Errors
app.error (err, req, res, next) ->
if err instanceof NotFound
res.send '404, not found.'
else
res.send '500, internal server error.'
app.get '/*', (req, res) ->
throw new NotFound
NotFound = (msg) ->
this.name = 'NotFound'
Error.call this, msg
Error.captureStackTrace this, arguments.callee
错误是
/home/techno/node/snaprss/application.coffee:22:5: error: unexpected if
if err instanceOf NotFound
^^
有人知道我的代码中的问题在哪里吗?
这个问题看起来有些相似
因此,请考虑在编辑器中检查制表符和空格。注意长缩进条件,例如:
if condition and other_condition and
yet_another_condition
^^
应该是
if condition and other_condition and
yet_another_condition
例如Intellij打破了这个缩进另一件事是要注意括号和大括号: Javascript
if (condition) {
//logic
}
应该是咖啡脚本
if condition
# logic
# END if
我的问题是我做了以下几件事:
myArray.map(行)->{
如果a等于“”
返回{}
}
问题是,除非返回对象,否则箭头函数不能有大括号。我的解决方案是拆除支架:
myArray.map(行)->
如果a等于“”
返回{}
我已通过使用不同的方法处理错误来解决我的错误问题。@techo这可能是缩进错误。我认为这是不正确的。。。至少是最新版本的咖啡脚本