Threaded View

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    12
    Vote Rating
    0
    masm is on a distinguished road

      0  

    Question Answered: What's the point in Ext.apply()?

    Answered: What's the point in Ext.apply()?


    Sorry, for the newcomer's stupid question, but I don't get what's the point in Ext.apply()?

    If it just copies provided properties to the specified object, what's the difference between following two snippets?
    Code:
    Ext.define('MyApp.LoginWindow',{
        extend:'Ext.Window',
    
        title:'Log in',
    
       initComponent:function(){
            Ext.apply(this,{
                items:[
                    {
                        xtype: 'textfield',
                        name : 'username',
                       fieldname: 'Username'
                    },
                    ...
                ]});
    }});
    Code:
    Ext.define('MyApp.LoginWindow',{
       extend:'Ext.Window',
    
        title:'Log in',
    
        items : [
            // as above
        ]
    
        initComponent:function(){
            ...
        }
    });

  2. In the 2nd one, you run the risk of those items being shared among all instances of that class. The first will always create a new array so the items are unique to each instance.