Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript CoffeeScript编译:如果_Javascript_Coffeescript - Fatal编程技术网

Javascript CoffeeScript编译:如果

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

我正在为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 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这可能是缩进错误。我认为这是不正确的。。。至少是最新版本的咖啡脚本