繁体   English   中英

Coffeescript + Express.js:无法调用未定义的“切片”方法

[英]Coffeescript + Express.js : cannot call method 'sliced' of undefined

我正在用express.js和coffeescript制作我的第一个应用程序。 该代码位于: https : //github.com/findjashua/contactlist

当我尝试运行它时,出现以下错误:

/Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/helpers.js:216
  codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end
                      ^
TypeError: Cannot call method 'slice' of undefined
  at Object.exports.prettyErrorMessage (/Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/helpers.js:216:27)
  at compileScript (/Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:199:25)
  at /Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:143:18
  at fs.js:266:14
  at Object.oncomplete (fs.js:107:15)

我假设这与contacts.coffee有关,但什么也没想。 有任何想法吗?

您永远不会关闭new ContactModel(的括号。

  exports.addContact = (req, res) ->
contact = new ContactModel(
    name: req.body.name
    phone: req.body.phone
contact.save((err) ->
    if not err
        console.log('created')
        res.send(contact)
    else
        res.send(error)
)

我的提示:忘记所有这些内容。 关于coffeescript的部分好处是,您可以使用缩进,而不会像源代码中的close parens那样包含大量浮动的结束定界符。 做就是了:

someFunction (arg1, arg2) ->
  body of nested function

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM