Results 1 to 3 of 3

Thread: Instantiating classes - this way or that way?

  1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    35

    Default Instantiating classes - this way or that way?

    Hi, I've seen the instantiating of a class done in 2 ways. eg

    1) (using xtypes) - items: [ {xtype: 'window', id: 'myWindow', ....} ]
    2) items:[ this.myWindow = new Ext.Window({ .... }) ]

    I prefere 2 because i can refer to the component by going 'this.myWindow' afterwards, as opposed to 'Ext.getCmp('myWindow')'

    Is there a downside to using 2? Is one way better than the other? I've read somewhere that you should always use xtypes where you can - why? does method 2 break this rule?

  2. #2
    Sencha User
    Join Date
    Dec 2010
    Posts
    139

    Default

    check http://www.sencha.com/learn/Tutorial:Xtype_defined

    It's for performance. Using xtypes will render a component when the user needs to see it, rather than creating them when the application is loaded.

    Try to avoid using ids, check out "ref" and "itemId".

  3. #3
    Sencha User
    Join Date
    Dec 2010
    Posts
    35

    Default

    Hi drian, thanks for your reply. It makes sense, but what about this...

    i've got a panel instantiated using an xtype, but one of its items is declared statically,
    so that I can simply reference it using ' this.myWindow' as opposed to getting it by itemId or Id.
    Is this acceptable/recommended? (sorry, the example is very arbitary)

    Code:
    {
     xtype: 'panel',
     title: 'My panel',
     items:[ this.myWindow = new Ext.Window({ .... }) ],
     listeners: {
        someEvent: function(){this.myWindow.show();}
     }
    }

Posting Permissions

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