Javascript 调用父视图';木偶中的s函数

Javascript 调用父视图';木偶中的s函数,javascript,backbone.js,marionette,Javascript,Backbone.js,Marionette,在木偶中,如何在不覆盖原始函数的情况下调用视图父对象上同名的函数 例如: var someView = new Backbone.Marionette.ItemView.extend({ onRender: function () { console.log('foo'); } }); var anotherView = someView.extend({ onRender: function () { // call someView

在木偶中,如何在不覆盖原始函数的情况下调用视图父对象上同名的函数

例如:

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();
var anotherView = someView.extend({
    onRender: function () {
        someView.prototype.onRender.call(this);
        console.log('bar');
    }
});
导致控制台输出:

foo
bar

您可以使用
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

或者直接引用要应用于实例的方法:

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();
var anotherView = someView.extend({
    onRender: function () {
        someView.prototype.onRender.call(this);
        console.log('bar');
    }
});

有关更多信息,请参见和。

因此,您不是指父视图(在树中),而是指继承自的
super
视图?这正是我要寻找的。谢谢你。请为你的第二个例子投票,在木偶2.0.0中,至少第一个例子说super未定义