3

I have a setup of multi level backbone inheritance, but would like to call back of the previous super class. Not sure if is possible.

Scenario:

BasicView -> MediumView -> HardView

Where I would love that when HardView created, it will loops to call previous super class initialize function.

Example is here:

http://jsfiddle.net/mochatony/bwB9W/

4

1 回答 1

4

标准 JavaScript 中没有对超类的隐式引用 - 您必须显式调用超类型的方法

var Basic = Backbone.View.extend({
    initialize: function(){
        console.log('base');
    }        
});


var Medium = Basic.extend({
    initialize: function() {
        console.log(Basic.prototype.initialize.apply(this, arguments));
        console.log('medium');
    }        
});

var Hard = Medium.extend({
    initialize:function(){        
        console.log(Medium.prototype.initialize.apply(this, arguments));
        console.log('hard');
    }        
});


var hard = new Hard();

​
于 2012-07-17T09:02:11.600 回答