我正在使用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 的好处之一是您可以使用缩进,而不需要像源代码中的右括号那样有大量的 float 结束定界符。只要这样做:
someFunction (arg1, arg2) ->
body of nested function
关于javascript - CoffeeScript + Express.js : cannot call method 'sliced' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17679817/