Ext JS: what is xtype good for?

前端 未结 5 1415
暖寄归人
暖寄归人 2021-01-31 09:07

I see there are lot\'s of examples in Ext JS where instead of actually creating Ext JS objects, an object literal with an xtype property is passed in.

What

5条回答
  •  野的像风
    2021-01-31 09:51

    An xtype is simply a name given to represent a class. It is a definition object which don't need to be instantiated when used in any part of application.

    While registering a xtype, we simply use this syntax: Ext.reg(,). But, we don't use the new keyword with the class name because the Component Mgr will automatically create instance of this class only if needed eg. in response to an event like click.

    We don't need to get an instance manually because after registering an xtype, the 'Component Mgr' will automatically create an instance for the class represtented by that xtype only if it is used anywhere in the application or it simply don't instantiate that class if not used elsewhere. Component Mgr runs this code:

    create : function(config, defaultType){
        return new types[config.xtype || defaultType](config);
    }
    

    xtype don't instantiate the class when Ext.Ready runs. But, new Ext.Container() will create all instances when Ext.Ready runs. So, using xtype is intelligent for large applications to get rid of garbage objects.

提交回复
热议问题