1. #1
    Sencha User
    Join Date
    Nov 2007
    Posts
    113
    Vote Rating
    8
    kerbo is on a distinguished road

      0  

    Default "New" vs. Ext.Create?

    "New" vs. Ext.Create?


    I am currently porting a 3.4 app to 4.1 and have 100's of lines of code like

    var frmId = new Ext.form.field.Text({...});

    In Ext 4.x, these calls could be converted to:

    var frmId = Ext.create('Ext.form.field.Text',{...});

    I understand maybe the benefits of using Ext.define/Ext.create for application classes but why use Ext.create for Ext classes?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,118
    Vote Rating
    855
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Ext.create will instantiate the class just like the new keyword will except it checks to see if the class has already been loaded. If not then it will load the file. Once it has made sure the class definition exists then it will create the instance.

    If you know the class is going to be loaded, using the new keyword is fine, I do it about 99% myself.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

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

    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.

Thread Participants: 1