Results 1 to 2 of 2

Thread: new Ext.Button(config) versus Ext.create('Ext.Button', config)

  1. #1
    Sencha User jep's Avatar
    Join Date
    Sep 2010
    Vote Rating

    Default Unanswered: new Ext.Button(config) versus Ext.create('Ext.Button', config)

    I have another best practices question. Say I'm creating a button dynamically one of two ways:

    var b = new Ext.Button(config);
    var b = Ext.create('Ext.Button', config)
    Since I'm creating both immediately, it's not a question of lazy instantiation. I'm also not using xtypes but specific class names ("Ext.Button"). Is there a best practice on which of these two methods to use? I see Ext.create does a whole bunch of stuff, though a lot of it is to allow you to use something other than straight-up class names. I'm not sure what else it does that might be important.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Best practices is to use Ext.create but I always use the new keyword as it is going to be more performant as you described Ext.create is doing some extra things to make sure the class is loaded. You just have to make sure you know the class is already loaded if you are going to use the new keyword.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2

    Think my support is good? Get more personalized support via a support subscription.

    Need more help with your app? Hire Sencha Services

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts