Fix for multiple inheritance #223

Closed
shagi opened this Issue Nov 30, 2012 · 2 comments

Projects

None yet

2 participants

shagi commented Nov 30, 2012

Currently the book recomends calling parent's initialize function with this.constructor.super.

var PanelAdvanced = Panel.extend({
    initialize: function(options){
        this.constructor.__super__.initialize.apply(this, [options])
        console.log('PanelAdvanced initialized');
        console.log(this.foo); // Log: bar
    }
});

However, when PanelAdvanced is also inherited, this example fails, entering a endless loop.

var PanelAdvancedExtra = PanelAdvanced.extend({
    initialize: function(options){
        this.constructor.__super__.initialize.apply(this, [options])
        console.log('PanelAdvancedExtra initialized');
    }
});

Calling parent's initialize more explicitly seems to fix the issue:

var PanelAdvanced = Panel.extend({
    initialize: function(options){
        Panel.prototype.initialize.call(this, [options])
        console.log('PanelAdvanced initialized');
        console.log(this.foo); // Log: bar
    }
});

var PanelAdvancedExtra = PanelAdvanced.extend({
    initialize: function(options){
        PanelAdvanced.prototype.initialize.call(this, [options])
        console.log('PanelAdvancedExtra initialized');
    }
});
Owner

@shagi Would you like to put this change together into a pull request so you can get credit for it?

shagi commented Dec 8, 2012

OK, I'll try.

@addyosmani addyosmani pushed a commit that closed this issue Dec 9, 2012
Addy Fixes #223 - multiple inheritance issue 6d3f9a4
@addyosmani addyosmani closed this in 6d3f9a4 Dec 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment