inheritance - Change defined arguments in inherited view in backbone.js -
i'm going inherit view following way
define('view1', ['backbone', 'jquery', 'subview1'], function(backbone, $, subview1){ var view1 = backbone.view.extend({ initialize: function() { //some code subview1 }, function1: function(){ //some code subview1 } }); return view1; } and child view
define('view2', ['backbone', 'jquery', 'view1', 'subview2'], function(backbone, $, view1, subview2){ var view2 = view1.extend({ initialize: function(e) { view1.prototype.initialize.apply(this, [e]); } }); return view2; } can somehow use subview2 instead of subview1 in child view or it's necessary rewrite functions it's used manually? 1 important thing, view1 cannot changed because provided third party library.
the easiest thing build view1 extensibility in mind. if store subview in prototype:
var view1 = backbone.view.extend({ //... subview: subview1 }); then view1 can refer this.subview instead of subview1 , subclasses can override subview property through prototype:
var view2 = view1.extend({ //... subview: subview2 }); and work expected.
for example: https://jsfiddle.net/ambiguous/ra52ssm4/
Comments
Post a Comment