在JS我有
$("#index").on({
click : function() { // do something useful with $(this)....}
},"li.superclass");
我怎么用CoffeeScript来描述这个?
在JS我有
$("#index").on({
click : function() { // do something useful with $(this)....}
},"li.superclass");
我怎么用CoffeeScript来描述这个?
它几乎是一样的:
$("#index").on click: ->
alert ("hi")
, "li.superclass"
它几乎是一样的:
$("#index").on click: ->
alert ("hi")
, "li.superclass"
mybe这是你想要的:
$("#index").on
click:->
alert "hi"
"li.superclass"
但我认为这更清楚:
events =
"click":->
alert "hi"
$("#index").on events, "li.superclass"
如果你需要使用 this
/@
在处理程序中,我认为你正在寻找像CoffeeScript的胖箭一样的东西 this
为你...
$('#index').on 'click', => alert(@)
请注意,您需要使用 off
删除处理程序或它可能不会被垃圾收集。 Backbone 0.9介绍 一个 listenTo
功能 这使得管理事件处理程序变得更加理智。