1

我正在 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有关,但想不出任何东西。有任何想法吗?

4

1 回答 1

1

你永远不会关闭括号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 的部分好处是您可以使用缩进,而不是像源代码中的右括号那样有大的浮动关闭分隔符链。做就是了:

someFunction (arg1, arg2) ->
  body of nested function
于 2013-07-16T16:23:39.013 回答