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
    Posts
    862
    Answers
    1
    Vote Rating
    24
      0  

    Default 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:

    Code:
    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
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    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! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Posting Permissions

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