是否有可能爲listenTo回調綁定函數參數?Backbone:如何綁定listenTo-callback的參數?
我到現在增加了一個包裝方法「將myHandler」我想擺脫:
// Basic marionette layout
var view = Marionette.Layout.extend({
initialize: function() {
// wrapping view logic inside a custom object
this.controller = new MyViewController();
},
// creates a sub view and adds event handlers
someFunc: function() {
var subView = new MySubView();
// HERE: how to bind args for callback?
this.listenTo(subView, "myEvent", this.myHandler, this);
},
// this is a dummy wrapper that I want to remove
myHandler: function(e) {
this.controller.handleIt(this, e);
},
我想要做的是一樣的東西:
someFunc: function() {
var subView = new MySubView();
// here wrapIt binds 'this' as first argument for handleIt
this.listenTo(subView, "myEvent",
wrapIt(this.controller.handleIt, this), this);
}
什麼是'this.controller.handleIt'? – 2013-04-30 07:17:08
@ Qantas94Heavy這是一個封裝視圖邏輯的FSM:[javascript-state-machine](https://github.com/jakesgordon/javascript-state-machine) – Fdr 2013-04-30 07:25:36
這些答案都有幫助嗎? – martin308 2013-10-09 23:16:27