Thursday, December 20, 2012

4 ways to call parent functions in backbone

Struggled with OOP concept in backbone.js when calling parent function, actually it is not backbone problem, but Javascript itself. After google, I found 4 most discussed ways to make sub class invoke parent class functions.

1. Use backbone plugin
this._super(attributes, options);

2. Use standard using Javascript style prototype

3. Use the internal __super__ property

4. Create _super function to Backbone Class
Backbone.Model.prototype._super = function(funcName){
    return this.constructor.__super__[funcName].apply(this,;
this._super('set', arg);

I suggest to use the plugin if possible.

1 comment: