Search code examples
inheritancemethodsbackbone.jsextend

Backbone extended view, extend method


How would I extend an extended view parent method not to override, keep parents method statements and add some custom code, here is the example case

var SomeView = View.extend({
  parentMethod: function() {
    //some parent code
  }
})


var MyView = SomeView.extend({
  parentMethod: function() {
     //keep parents statements and extend
  }
})

Solution

  • JavaScript does not provide a simple way to call super — the function of the same name defined higher on the prototype chain. If you override a core function like set, or save, and you want to invoke the parent object's implementation, you'll have to explicitly call it

    http://backbonejs.org/#Model-extend

       var MyView = SomeView.extend({
          parentMethod: function() {
             SomeView.prototype.parentMethod.apply(this, arguments);
             //some additional logic
          }
        })