我正在玩弄在 Backbone.js 中实现Facade和Mediator模式的光环( http://github.com/addyosmani/backbone-aura)示例。我希望有人熟悉这个概念。我正在尝试读取变量(例如,在此示例中,我在外观的renderComplete部分中。我(如果可能的话)如何访问 Appview 的函数/变量?
console.log(this.i); 返回一个未定义的,所以我猜我在某处失去了范围
define([
'jquery',
'underscore',
'backbone',
'text!templates/master.html',
'../aura/mediator',
'../aura/facade',
'../subscriptions'
], function($, _, Backbone, masterTemplate, Mediator, Facade){
var AppView = Backbone.View.extend({
el: "body",
i : 5,
template: _.template(masterTemplate),
facade: {
routeChange: Facade.extend("masterViewChange", "routeChanged", function(route){
console.log("Change view to " + this.i);
}),
renderComplete: Facade.extend("postMasterRender", "masterRendered", function(){
console.log(this.i);
})
},
events: {},
initialize: function() {
this.render();
Mediator.publish("masterRendered", this);
},
render: function() {
$(this.el).html(this.template());
}
});
return AppView;
});