EXTJS 5 學習筆記1

1. Name Conventions 命名規范

     1) Classes 類          a. 類名只能包含數字字母 only contain alphanumeric characters          b. 允許但不鼓勵使用數字  numbers are permitted but discouraged          c. 不能使用下划線、減號或其他特殊字符          d. 類要按包名組織,至少需要一個最頂層的唯一包名          e. 最頂層的包名和類名應該大小寫,其他中間名字需小寫 top-level namespaces and the actual class names should be CamelCased          f.  縮略詞也應該遵循大小寫原則          g. 非Sencha發布的類不允許使用Ext作為最頂層的包名        2) Source Files  源文件          a. 類名直接映射成文件路徑 names of classes map directly to the file paths          b. 一個類一個文件          c. Ext.util.Observable => /path/to/src/Ext/util/Observable.js        3) Methods and Variables 方法與變量          a. 方法與變量名只能包含數字字母 only contain alphanumeric characters          b. 允許但不鼓勵使用數字  numbers are permitted but discouraged          c. 不能使用下划線、減號或其他特殊字符        4) Properties 屬性          a. 屬性的命名規范與變量的命名規范類似          b. 靜態屬性的名稱必須全部大寫     2. Declaration 聲明      1) The Old Way          a. var MyClass = Ext.extend(object, {...});          b. Ext.ns("My.cool");  My.cool.Window = Ext.extend(Ext.Window, {...});        2) The New Way          a. Ext.define(className, members, onClassCreated);          b. Ext.create(className, arguments);   3. Configuration 配置      1) As for EXTJS 4, a dedicated config property was introduced      2) Configurations are completely encapsulated from other class members      3) Getter and setter methods for every config property are automatically generated into the class prototype during class creation if methods are not already defined      4) The auto-generated setter method calls the applyXXX method (if defined on the class) internally before setting the value. You may override the applyXXX method for a config property if you need to run custom logic before setting the value. If your apply method does not return a value, the setter will not set the value. The updateXXX method (if defined) will also be called when a different value is set. Both the applyXXX and updateXXX methods are passed the new value and the old value as params.      5) As for EXTJS 5, eliminated the need to call initConfig() manually. Only for your own classes that extend Ext.Base, initConfig() still neneds to be called   4. Statics 靜態成員      1) 通過配置statics來定義靜態成員 static members can ben defined using the statics config      2) Ext.define('Computer', {               statics: {                     instanceCount: 0,                     factory: function(brand) {                          return new this({brand: brand});                     }                },                                config: {                     brand: null                }          });          var dell = Computer.factory('dell');   5. Errors Handling & Debugging 錯誤處理及調試      1) 通過Ext.getDisplayName()獲取方法的名稱。尤其是在需要拋出異常           throw new Error('['+ Ext.getDisplayName(arguments.callee) +'] something wrong ');      2) 使用Ext.define()定義的任意類方法在拋出異常時,可以在WebKit瀏覽器上觀察到異常棧(Chrome/Safari)



粤ICP备14056181号  © 2014-2021 ITdaan.com