Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:03:04+00:00 2026-05-26T03:03:04+00:00

I have a view called Pannel which is just a background with a close

  • 0

I have a view called Pannel which is just a background with a close button. I want to extend that view to one called PannelAdvanced. How would I do that with backbone.js?

Right now all the examples have Backbone.View.Extend but those just extend Backbone.View; I want to extend my PannelView.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:03:04+00:00Added an answer on May 26, 2026 at 3:03 am

    The easiest way to inherit a view is to do what other people have already suggested in the comments:

    var Pannel = Backbone.View.extend({
    });
    
    var PannelAdvanced = Pannel.extend({
    });
    

    But like you’ve noted in your comments, if you have an initialize method in Pannel, then it won’t be called if you also have an initialize method in PannelAdvanced, so you have to call Pannel’s initialize method explicitly:

    var Pannel = Backbone.View.extend({
       initialize: function(options){
          console.log('Pannel initialized');
          this.foo = 'bar';
       }
    });
    
    var PannelAdvanced = Pannel.extend({
       initialize: function(options){
          Pannel.prototype.initialize.apply(this, [options])
          console.log('PannelAdvanced initialized');
          console.log(this.foo); // Log: bar
       }
    });
    

    It’s a bit ugly because if you have a lot of Views that inherit from Pannel, then you’ll have to remember to call Pannel’s initialize from all of them. Even worse, if Pannel doesn’t have an initialize method now but you choose to add it in the future, then you’ll need to go to all of the inherited classes in the future and make sure they call Pannel’s initialize. So here’s an alternative way to define Pannel so that your inherited views don’t need to call Pannel’s initialize method:

    var Pannel = function (options) {
    
        // put all of Panel's initialization code here
        console.log('Pannel initialized');
        this.foo = 'bar';
    
        Backbone.View.apply(this, [options]);
    };
    
    _.extend(Pannel.prototype, Backbone.View.prototype, {
    
        // put all of Panel's methods here. For example:
        sayHi: function () {
            console.log('hello from Pannel');
        }
    });
    
    Pannel.extend = Backbone.View.extend;
    
    
    // other classes inherit from Panel like this:
    var PannelAdvanced = Pannel.extend({
    
        initialize: function (options) {
            console.log('PannelAdvanced initialized');
            console.log(this.foo);
        }
    });
    
    var pannelAdvanced = new PannelAdvanced(); //Log: Pannel initialized, PannelAdvanced initialized, bar
    pannelAdvanced.sayHi(); // Log: hello from Pannel
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a view called View Story which is just a web
I would like to have one view called Example and have the ability to
I have a view called gallery that options. I want to listen and act
We have a View (call it X) that is the base view called by
I have a view and template called index.html. I have a image which is
I have a view called MyViewController, that I initialize from a xib file. Its
I am new to iPhone development. I have a view called barView which is
I have a partial view called Login.ascx that has my login boxes that I
I have created a view called RoundedImageView, the corners are rounded. I want an
I have a View (called MyView) in my Layout file. I want to content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.