在Marionette.js中调用父视图的函数
-
21-12-2019 - |
题
在marionette中,我如何在视图的父对象上调用相同名称的函数而不覆盖原始函数?
例如:
var someView = new Backbone.Marionette.ItemView.extend({
onRender: function () {
console.log('foo');
}
});
var anotherView = someView.extend({
onRender: function () {
// call someView's original onRender function
console.log('bar');
}
});
anotherView.render();
.
导致控制台输出:
foo
bar
. 解决方案
您可以使用 __super__
:
var anotherView = someView.extend({
onRender: function () {
this.__super__.onRender.call(this);
console.log('bar');
}
});
.
或只是直接引用要在实例上应用的方法:
var anotherView = someView.extend({
onRender: function () {
someView.prototype.onRender.call(this);
console.log('bar');
}
});
.
有关更多信息,请参阅函数的JavaScript类继承和什么生成的generacicetagcode do
不隶属于 StackOverflow