如何在 coffeescript 中编写文字 jQuery 对象
How to write literal jQuery object in coffeescript
我正在尝试将一些代码转换为coffeescript,但我遇到了问题:
var $el = $('<span/>', {
class : 'myclass',
click : function () {
var $this = $(this)
if (foo) { // radio & check
baz($this)
}else{
bla($this)
}
}
});
我在咖啡里是这样写的:
$el = $('<span/>',
class: 'myclass'
click: ->
$this = $(this)
if foo
baz $this
else
bla $this
)
这工作得很好,但我真的很不喜欢最后一个括号,有什么办法可以编写没有参数的代码,只是缩进?
如果去掉两个括号,工作正常。
$el = $ "<span/>",
class: "myclass"
click: ->
$this = $(this)
if foo
baz $this
else
bla $this
另请参阅:http://js2coffee.org/
相关文章:
- 如何使用jQuery以文字显示现金价值
- jQuery:如何使用文字对象方法中的方法来获取全局变量
- 在IE 7中,如果链接是使用jQuery创建的,如何获取链接的href属性的文字值
- 如何在 coffeescript 中编写文字 jQuery 对象
- 文字对象和jquery选择器DRY
- jQuery 对象文字模式
- 比较两个字符串(jquery .text() 和文字字符串)
- 使用jQuery.prop&对象文字-两种不同的结果
- SyntaxError:jquery中未终止的字符串文字
- jQuery.html()方法函数文字参数
- jquery对象文字函数/闭包-缺少一些明显的东西
- jQuery出现未终止的字符串文字错误
- 正在转义jQuery DateTime选取器中的文字
- jquery附加了很多html(得到“未终止字符串文字”或“错误转义”错误)
- javascript对象文字和jquery各一个
- JQuery.each将字符串文字转换为字符串.为什么?
- jQuery对象文字函数声明错误
- Javascript/Jquery对象文字版本,对变量请求执行函数
- jQuery.如何将JS变量与标签文字组合在一起?
- 对象文字jquery事件范围