---
title: "Extjs createDelegate 方法使用"
author: "fengchong719"
date: "2010-06-07T14:55:05Z"
tags: ["EXT"]
categories: ["Web前端"]
slug: "extjs-createdelegate"
draft: false
lastmod: "2010-06-07T14:55:58Z"
id: 686017
url: "https://feng-henry.iteye.com/blog/686017"
---

关于Extjs 的 createDelegate我也接触不久。
我们自己写一个组件，使用继承时。我们会在继承中写：

```js

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这个作用域运行。