Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending Custom Backbone View

Using

Backbone.View.extend

I have created a Backbone View called MyView. In my view I've created a bunch of custom functions. The problem I'm having is that I need to create a new Backbone view that extends MyView.

I don't want to create a new View and duplicate code... I just want to utilize inheritance to extend functionality... Problem is that I don't know the way to do it exactly, and I also don't know how to call the super functions in Backbone.

*Edit - Thanks for the answers by some below, but still not quite sure how to call parent's method. For example:

// in subView
{
initialize: function(){
// would like to do something like super.initialize()
 // here i would then declare variables exclusive to subview
}
like image 296
K2xL Avatar asked Apr 10 '12 17:04

K2xL


1 Answers

I think what you're looking for is:

 var NewView = MyView.extend({
     //Usual config goes on in here, and it will have inherited functions
     //And default properties from MyView
 });

Or, if you are looking to call the super class then there is an implementation of it here: http://forrst.com/posts/Backbone_js_super_function-4co

like image 123
Dan Prince Avatar answered Oct 15 '22 11:10

Dan Prince