2014년 12월 5일 금요일

Performance Tip

Creating Instances on the Prototype is Bad

by Mitchell Simoens
When defining a new class using Ext.define, you should never use Ext.create to create an instance on the prototype like this:
 
Ext.define(‘MyApp.view.Main, {
    extend : ‘Ext.container.Container,
    xtype  : ‘myapp-main’,
 
    requires : [
        ‘MyApp.plugins.Foo],
 
    items : [
        Ext.create(‘Ext.Component, {
            html : ‘Hello’
        })
    ],
 
    plugins : [
        Ext.create(‘MyApp.plugins.Foo)
    ]
});
 
Instead, you should use configuration objects with a class alias:
 
Ext.define(‘MyApp.view.Main, {
    extend : ‘Ext.container.Container,
    xtype  : ‘myapp-main’,
 
    requires : [
        ‘MyApp.plugins.Foo
    ],
 
    items : [
        {
            xtype : ‘component’,
            html  : ‘Hello’
        }
    ],
 
    plugins : [
        {
            ptype : ‘myapp-foo’
        }
    ]
});
 

댓글 없음:

댓글 쓰기