ExtJS 的event handler的scope

var button = Ext.create('Ext.button.Button', {
   text: 'My Test Button',
   listeners: {
      click: function(button, e, options){
          alert(this.text);
      }
   },
   renderTo: Ext.getBody()
});

button.show();



上面的代码结果是My Test Button

var exampleObject = {
   text: 'My Test Object'
};
var button = Ext.create('Ext.button.Button', {
   text: 'My Test Button',
   listeners: {
      click: function(button, e, options){
          alert(this.text);
      },
      scope: exampleObject
   },
   renderTo: Ext.getBody()
});

button.show();


上面的结果是My Test Oject

你可能感兴趣的:(JavaScript,ExtJs)