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

  • SEARCH
  • Home
  • 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 882305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:24:23+00:00 2026-05-15T12:24:23+00:00

I am trying to get better at extending the classes of Extjs , and

  • 0

I am trying to get better at extending the classes of Extjs, and my evolvement have lead me to this problem:

I have extended an Ext.Panel and I want my extension to have a bottom toolbar with one button as default.

myPanel = Ext.extend(Ext.Panel, {
    method: function () {
        return 'response!';
    },

    bbar: new Ext.Toolbar({
        items:
        [
            {
                xtype: 'button',
                text: 'Hit me!',
                handler: function (button, event) {
                    alert(this.method());
                },
                scope: this
            }
        ]
    })
});

What I haven’t learnt yet is why this is not allowed. this is pointing at the global scope and not my extended panel – thus .method() is undefined inside the handler function.

  • 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-15T12:24:24+00:00Added an answer on May 15, 2026 at 12:24 pm

    You’re defining the bbar on the prototype rather than on a specific object.

    Override initComponent and move the bbar definition inside it.

    myPanel = Ext.extend(Ext.Panel, {
        method: function () {
            return 'response!';
        },
    
        initComponent: function() {    
            var bbar = new Ext.Toolbar({
                items:
                [
                    {
                        xtype: 'button',
                        text: 'Hit me!',
                        handler: function (button, event) {
                            alert(this.method());
                        },
                        scope: this
                    }
                ]
            });
    
            // Config object has already been applied to 'this' so properties can 
            // be overriden here or new properties (e.g. items, tools, buttons) 
            // can be added, eg:
            Ext.apply(this, {
                bbar: bbar
            });
    
            // Call parent (required)
            myPanel.superclass.initComponent.apply(this, arguments);
    
            // After parent code
            // e.g. install event handlers on rendered component
        }
    });
    

    See http://www.sencha.com/learn/Manual:Component:Extending_Ext_Components for a template you can use when extending components

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a C programmer and trying to get better at C++. I want to
I am trying to get a better working knowledge of JavaScript. So, I have
I'm really trying to get better with this stuff. I'm pretty functional with internationalization
I'm trying to get a better understanding of how endpoints work. I've read this
I'm trying to get some better logic behind this before I start writing code.
I am trying to get a better idea on this as so far I
I've been trying to get a better grasp on jQuery and have been coming
I'm trying to get better performance out of this Oracle query (which is terribly
I'm trying to get better at unit testing my JavaScript. I have the following
OK, I am just trying to get better at making more loosely coupled classes

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.