【问题标题】:CoffeeScript not passing variableCoffeeScript 没有传递变量
【发布时间】:2014-01-09 00:14:02
【问题描述】:

各位, 试图弄清楚这两个语句之间的区别,以及为什么一个有效,另一个抛出错误:

作品:

jsonFileContents = fs.readFileSync('sample.json', 'utf8')
res.send(jsonFileContents)

没有:

jsonFileContents = fs.readFileSync('sample.json', 'utf8')
returnResult(jsonFileContents)

returnResult = (data) ->
    res.send data

抛出错误:

`TypeError: undefined is not a function`

【问题讨论】:

  • 伙计们,我完全知道这个函数是同步的 :) 只是在这里测试一些东西,看到这个,我想问一下 :) 谢谢!

标签: coffeescript


【解决方案1】:

这是因为使用时没有定义returnResult。

以下应该有效:

returnResult = (data) ->
    res.send data

jsonFileContents = fs.readFileSync('sample.json', 'utf8')
returnResult(jsonFileContents)

【讨论】:

  • 那么通过将 returnResult 放在调用上方可以解决这个问题?
  • @Cmag 是的,因为那样 returnResult 在你使用之前就已经定义好了。
猜你喜欢
  • 2012-10-18
  • 2018-11-07
  • 1970-01-01
  • 1970-01-01
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多