我正在尝试熟悉CoffeeScript和backbone.js,而且我一定是缺少某些东西.
这个咖啡脚本:
MyView = Backbone.View.extend events: { "click" : "testHandler" } testHandler: -> console.log "click handled" return false view = new MyView {el: $('#test_container')} view.render()@H_403_5@生成以下JavaScript:
(function() { var MyView,view; MyView = Backbone.View.extend({ events: { "click": "testHandler" },testHandler: function() { console.log("click handled"); return false; } }); view = new MyView({ el: $('#test_container') }); view.render; }).call(this);@H_403_5@但是当我点击test_container时,点击事件不会触发testHandler.
如果我将输出JavaScript更改为:
$(function() { var MyView,testHandler: function() { console.log("click handled"); return false; } }); view = new MyView({ el: $('#test_container') }); view.render; });@H_403_5@