关于Extjs 的 createDelegate我也接触不久。
我们自己写一个组件,使用继承时。我们会在继承中写:
当然,如果在按钮的事件那里写this.showMessage是不行的。
这个方法跟call方法相当,是把这个方法放到this这个作用域运行。
我们自己写一个组件,使用继承时。我们会在继承中写:
Ext.MyCmp = function(config){
Ext.apply(this,config);
this.message = 'show message method run';
this.buttons = [
{
xtype:'button',
text:'click',
handler:this.showMessage.createDelegate(this)
}
];
Ext.MyCmp.superclass.constructor.call(this);
}
Ext.extend(Ext.MyCmp,Ext.Window,{
showMessage : function(){
Ext.Msg.alert('提示',this.message);
}
});
当然,如果在按钮的事件那里写this.showMessage是不行的。
这个方法跟call方法相当,是把这个方法放到this这个作用域运行。