简体   繁体   English

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

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

I'm making my first app in express.js and coffeescript. 我正在用express.js和coffeescript制作我的第一个应用程序。 The code is at: https://github.com/findjashua/contactlist 该代码位于: https : //github.com/findjashua/contactlist

When I try to run it, I get the following error: 当我尝试运行它时,出现以下错误:

/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)

I'm assuming it's something to do with contacts.coffee, but can't think of anything. 我假设这与contacts.coffee有关,但什么也没想。 Any ideas? 有任何想法吗?

You never close the parens for new ContactModel( . 您永远不会关闭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)
)

My tip: forget all these parens. 我的提示:忘记所有这些内容。 Part of the nice thing about coffeescript is you can use indentation and not have big chains of floating closing delimiters like the close parens in your source. 关于coffeescript的部分好处是,您可以使用缩进,而不会像源代码中的close parens那样包含大量浮动的结束定界符。 Just do: 做就是了:

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

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

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