Backbone 扩展视图,扩展方法
Backbone extended view, extend method
我如何扩展扩展视图父方法而不覆盖,保留父方法语句并添加一些自定义代码,这里是示例
var SomeView = View.extend({
parentMethod: function() {
//some parent code
}
})
var MyView = SomeView.extend({
parentMethod: function() {
//keep parents statements and extend
}
})
JavaScript does not provide a simple way to call super — the function
of the same name defined higher on the prototype chain. If you
override a core function like set, or save, and you want to invoke the
parent object's implementation, you'll have to explicitly call it
http://backbonejs.org/#Model-extend
var MyView = SomeView.extend({
parentMethod: function() {
SomeView.prototype.parentMethod.apply(this, arguments);
//some additional logic
}
})
我如何扩展扩展视图父方法而不覆盖,保留父方法语句并添加一些自定义代码,这里是示例
var SomeView = View.extend({
parentMethod: function() {
//some parent code
}
})
var MyView = SomeView.extend({
parentMethod: function() {
//keep parents statements and extend
}
})
JavaScript does not provide a simple way to call super — the function of the same name defined higher on the prototype chain. If you override a core function like set, or save, and you want to invoke the parent object's implementation, you'll have to explicitly call it
http://backbonejs.org/#Model-extend
var MyView = SomeView.extend({
parentMethod: function() {
SomeView.prototype.parentMethod.apply(this, arguments);
//some additional logic
}
})