1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    108
    Vote Rating
    1
    Notepad123 is an unknown quantity at this point

      0  

    Default Overriding class properties: config vs listeners

    Overriding class properties: config vs listeners


    How come that when I create new Object and provide new config parameter as shown in the below example this config parameter will not completely override config defined in a class. Instead properties defined in new config will simply get added to the proeprties already defined in class config.

    Code:
    Ext.setup({  
    
    
      onReady        : function() {
        
        //CREATE BUTTON..
        var myButton = Ext.create('MyButton', {
          text : 'New Text from Object'
        });
                       
        //CREATE PANEL.
        Ext.create('Ext.Panel', {      
          fullscreen : true,      
          items      : [myButton]            
        });
        
        //myButton.setText('New Text');
        console.log('text  = ',myButton.getText ());
        console.log('title = ',myButton.getTitle());
            
      }
    
    
    });
    MyButton.js
    Code:
    //CLASS DEFINITION.Ext.define('MyButton', {
      
      //PARENT CLASS FROM WHICH IT INHERETS FUNCTIONALITY.
      extend     : Ext.Button,
      
      //SPECIAL PROPERTIES FOR WHICH SETTERS, GETTERS AND OTHER STUFF IS CREATED.
      config     : {
        title    : 'Button Title',
        text     : 'My Button'
      }
    
    });

    But if you were to provide listeners property inside config then this would completely replace listeners property defined in class. I know I already have few threads concerning this but in this thread I wanted to focus how this behaviour doesn't seem consistent - object config doesn't override class config but object listeners will override class listeners. I am just trying to make sense of things. I am not just interested in how things currently work but also in why are they working like this and would it make more sense to work in a more consistent manner. What I am saying is that maybe this listeners subproperty might have some special handling to behave more like config behaves.

  2. #2
    Sencha - Support Team
    Join Date
    Oct 2011
    Posts
    3,955
    Vote Rating
    131
    fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all

      0  

    Default


    When you pass a config in on Ext.create you are only changing it in that instance.
    Listeners should not be defined within the config object.
    Get more personalized support via a support subscription.

    Want to learn Sencha Touch 2? Check out
    Sencha training
    Sencha Touch in Action

    Need more help with your app? Hire Sencha Services services@sencha.com

    When posting code, please use BBCode's CODE tags.

    Need to include a test case use:
    The official Sencha Fiddle

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    108
    Vote Rating
    1
    Notepad123 is an unknown quantity at this point

      0  

    Default


    Yeah, I know that there are only changed in that instance.
    This is why I created this thread.
    I wanted to know if I could somehow change those listeners in the class itself so that instances later created would have new listeners and if already created instances will preserve old listeners or if they will change to new ones.
    In other words just like you can add new listeners to Objects by using on() is there some other method that adds listener to the class itself.

Thread Participants: 1