ExtJS learning ------- Ext. define alias and slave name, two methods to define static methods, mixed attributes and other attributes
(1) Ext. define alias and backup name
Ext. onReady (function () {Ext. define ('user', {config: {name: 'zhang san', age: 23}, // use the alias: 'Alias _ user', // use the alternate name alternateClassName: 'alternateclassname _ user', constructor: function (config) {// constructor var me = this; me. initConfig (config) ;}}); // use three names to define var u1 = Ext. create ('user'); var u2 = Ext. create ('Alias _ user'); var u3 = Ext. create ('alternateclassname _ user'); alert (u1.getName () + '=' + u1.getAge (); alert (u2.getName () + '=' + u1.getAge (); alert (u3.getName () + '=' + u1.getAge ());});
Result:
(2) define static methods (two methods)
Ext. onReady (function () {Ext. define ('person', {config: {name: 'zhang san'}, statics: {// static method or attribute static_id: 'I am the id of Person, the quilt class cannot be inherited !! '}, InheritableStatics: {// static method or attribute inheritableStatics_id:' I am the id of Person, And I can inherit from the quilt class !! '}, Constructor: function (config) {var me = this; me. initConfig (config) ;}}); Ext. define ('user', {extend: 'person ', config: {age: 23}); // test the inherited static attributes: the instance object cannot use static attributes or methods // use the class name to use static attributes or methods alert (User. static_id); alert (User. inheritableStatics_id); alert (Person. static_id );});
Result:
(3) adding attributes is equivalent to multi-inheritance:
Ext. onReady (function () {Ext. define ('boys', {boySay: function () {alert ('I am a Boy... ') ;}}); Ext. define ('girl ', {girlSay: function () {alert (' I am a Girl... ') ;}}); Ext. define ('person', {mixins: {//, equivalent to inheriting boy: "Boy", girl: "Girl"}); var p = Ext. create ('person '); p. boySay (); p. girlSay ();});
Result:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + partition = "http://www.2cto.com/uploadfile/Collfiles/20140821/20140821104810196.png" alt = "">