我正在尝试使用以下代码动态重写该方法。
"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
谁能解释一下到底发生了什么?