extjs - Sencha touch 2 Event listeners in Ext.Define -
i reading sencha docs event handling , listeners config. in documentation of the listener config found note :
note: bad practice specify listener's config when defining class using ext.define(). instead, specify listeners when instantiating class ext.create().
i have seen number of s.o. answers have listeners in ext.define()
.
also came accross blog post the evils of ext.define , listeners think more relevant ext-js sencha touch 2. , new sencha touch.
can explain difference cons of adding listeners in ext.define() , difference make?
the problem pretty basic. if have listener
property in class, moment create instance of class , add listener
property particular instance, gong override ext.define 's listener property. this:
var obj = { foo: { bar : 'hello world' } }; obj = ext.merge(obj, { // here ext.merge show how 2 objects can merged foo : 'i got changed!' });
will bar
property of foo
object? no. identical properties overridden. similar things happen listeners too.
ext.define('abc', { config : { listeners : { 'tap' : ext.emptyfn } } }); var newpanel = ext.create('abc', { listeners : { 'activate' : ext.emptyfn } });
the config object pass in ext.create
merged config object of ext.define
. so, better choice not use listener
property in ext.define
.
Comments
Post a Comment