CoffeeScript 中的匿名函数赋值
我正在努力使以下代码正常工作:
class Elements
constructor: ->
loadAll: ->
success = (data) =>
doSomething
doSomethingElse
$.post bla success
它认为 doSomething 之后的所有内容都不是成功回调正文的一部分。
编辑:我没有意识到 CS 对空格/制表符敏感。 TextMate 对此没有帮助;有没有更好的CS IDE?
I'm struggling to make the following code work:
class Elements
constructor: ->
loadAll: ->
success = (data) =>
doSomething
doSomethingElse
$.post bla success
It thinks everything after doSomething is not part of the success callback body.
Edit: I didn't realise CS was space/tab sensitive. TextMate doesn't help with it; Is there a better IDE for CS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TextMate 可能是 CoffeeScript 的最好编辑器,其捆绑包由 CoffeeScript 创建者 Jeremy Ashkenas 维护。 (该捆绑包还与 Sublime Text 2 兼容,这是一个很好的跨平台替代方案。)这里的解决方案是:
这样,当您按 Tab 键时,就会插入指定数量的空格。通过避免使用实际的制表符,您可以避免由于 n 个空格在人类看来与 1 制表符相同但对编译器来说却含糊不清而导致的不可避免的混乱。
CoffeeScript 社区的标准是 2 个空格,但也有很多人使用 4 个空格(这是 Python 领域的官方标准);只需选择一个并坚持下去即可。
如果您决定切换到 Sublime Text 2,您可以将这些行添加到您的
Base File.sublime-settings
首选项文件中,以强制使用给定空格数的软制表符:总而言之:硬带有大量空白的选项卡和语言不能混合。配置您的编辑器以负责任地使用软选项卡和 CoffeeScript。 :)
TextMate is probably the best editor for CoffeeScript, with a bundle maintained by CoffeeScript creator Jeremy Ashkenas. (The bundle is also compatible with Sublime Text 2, which is a nice cross-platform alternative.) The solution here is to:
That way, when you hit the Tab key, the number of specified spaces is inserted. By avoiding the use of actual tab characters, you avoid the inevitable confusion that results from n spaces looking the same to a human as 1 tab, but being ambiguous to the compiler.
The norm in the CoffeeScript community is 2 spaces, but there are plenty of folks using 4 spaces (which is the official standard in Python-land); just pick one and stick with it.
If you do decide to make the switch to Sublime Text 2, you can add these lines to your
Base File.sublime-settings
preferences file to force soft tabs with the given number of spaces:In sum: Hard tabs and languages with significant whitespace don't mix. Configure your editor to use soft tabs, and CoffeeScript responsibly. :)