CoffeeScript功能

时间:2012-01-23 18:42:30

标签: coffeescript

我正在阅读这本光滑的CoffeeScript书,它有一个代码

confirm 'Shall we, then?', (answer) -> show answer

这应该从确认中得到答案并显示它/我将'show'更改为console.log并且它似乎没有执行它。我错过了什么。

感谢

1 个答案:

答案 0 :(得分:3)

confirm()不接受回调。除非这个人做出了自己的确认功能,否则无法正常工作。编译的cs

confirm("Shall we, then?", function(answer) {
  return console.log(answer);
});

confirm()会返回truefalse,因此您只需将其用作条件。

console.log "They answered yes" if confirm "Shall we, then?"
相关问题