javascript - Call a parent view's function in Marionette.js -
in marionette, how might go calling function of same name on parent object of view without overwriting original function?
for instance:
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();
resulting in console output:
foo bar
you can use __super__
, set extend
:
var anotherview = someview.extend({ onrender: function () { this.__super__.onrender.call(this); console.log('bar'); } });
or directly reference method want apply on instance:
var anotherview = someview.extend({ onrender: function () { someview.prototype.onrender.call(this); console.log('bar'); } });
for more information, see javascript class inheritance functions , what .call()
does.
Comments
Post a Comment