1
我正在嘗試使用以下代碼動態地重寫該方法。重寫方法無法正常工作
"use strict";
define(function (require) {
var Backbone = require('backbone');
var TestView = Backbone.View.extend({
initialize: function() {
var that = this;
that.model.on("change", this.render, this);
},
render: function() {
this.initialRender();
this.$el.html("Work to do everytime");
this.render = function() {
this.$el.html("Work to do everytime");
}
},
initialRender: function() {
console.log("Work to do once only");
}
});
var model = new Backbone.Model();
var view = new TestView({
model: model
});
view.render();
view.render();
view.model.set("testdata", "data");
});
我想這樣的輸出:
Work to do once only
但我得到這樣的輸出:
Work to do once only
Work to do once only
誰能請解釋一下,究竟是怎麼回事?
謝謝..得到了問題。 – 2013-03-12 09:25:35