ExtJS learning ------- Ext. define alias and slave name, two methods to define static methods, mixed attributes and other attributes

Source: Internet
Author: User

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 = "">





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.