【发布时间】:2012-04-20 21:35:14
【问题描述】:
我正在研究在 Backbone.js 中实现 Facade 和 Mediator 模式的 aura(http://github.com/addyosmani/backbone-aura) 示例。我希望有人熟悉这个概念。我正在尝试读取变量(例如 i 在此示例中位于外观的 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;
});
【问题讨论】:
标签: javascript design-patterns backbone.js requirejs facade