『ExtJS』01 009. ExtJS 4 方法重载

在ExtJS中,使用Ext.override方法对已有类方法的重载。

如何去做


  1. 定义一个类,并给他一个方法

       1: Ext.define('Simple.Class',{
       2:     welcome:function(){
       3:         alert('Welcome to the app');
       4:     }
       5: });
  2. 使用Ext.override方法对已有类进行重载并添加函数

       1: Ext.override(Simle.Class,{
       2:     goodBye:function(){
       3:         alert('Goodbye');
       4:     },
       5:     funAll:function(){
       6:         this.welcome();
       7:         this.goodBye();
       8:     }
       9: });
  3. 实例化类对象,并调用新的方法

       1: var app = new Simple.Class();
       2: app.runAll();   //Welcome to the app     Goodbye
  4. 重载的另一种写法

       1: Simple.Class.override({
       2:    // New members...
       3: });
posted @ 2012-11-29 14:48  莫不逢  阅读(1044)  评论(0编辑  收藏  举报