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

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

你永远不会closuresnew 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) ) 

我的提示:忘记所有这些parens。 关于coffeescript的好处之一是你可以使用缩进,而不是像你的源代码中的closures分隔符那样拥有大的closures分隔符链。 做就是了:

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