(1) Succession of Ext.define extend
Specific examples:
Ext.onready (function () {//sup class parent ext.define (' person ', {config:{name: ' BJSXT '}, constructor:function (config) {var me = this; Me.initconfig (config);}); /sub class Subclass Ext.define (' Boy ', {//using EXT's inheritance Extend: ' person ',//Direct inheritance Config:{sex: ' Male ', age:20}}), var B = ext.create (' Boys ', { Name: ' Zhang San ', age:25}); alert (' Name: ' +b.name+ '--Gender: ' +b.sex+ '--Age: ' +b.age ');});
Example Results:
(2) Use JavaScript achieve similar Ext The Inheritance
Instance:
Ext.onready (function () {//javascript:prototype (prototype): implementation inherits//supclassvar person = function (name) {this.name = name;};// alert (Person.prototype.constructor);//constructor of the prototype object, default is the template of the current class//supclass prototype Objectperson.prototype = { Constructor:person, Id:100};//subclassvar boy = function (name,sex,age) {//How to borrow constructor inheritance Person.call (This,name); This.sex = sex; this.age = age;};/ /Implement prototype Inheritance: inherits the template of the parent class and the prototype object of the parent class//boy.prototype = new Person ();//Implement Extend Method function Myextend (sub, sup) {var F = Functi On () {},//defines an empty function as a prototype object of the subclassproto,//subclass of the relay function//The prototype object of the parent class is given the Superclassproto variable Superclassproto = Sup.prototype; The location of the relay: The prototype object of the parent class is assigned to the prototype object of the empty function of f//prototype inheritance f.prototype = Superclassproto; Subclassproto = Sub.prototype = new F (); Subclassproto.constructor = sub;//Restore Constructor Sub.superclass = superclassproto;//do a save, save the prototype object of the parent class//The purpose is to prevent you from careless if (Superclassproto.constructor = = = Object.prototype.constructor) {superclassproto.constructor = sup; }};myextend (boy, person);//implementation of the method of inheritance var B = new boy (' John Doe ', ' Male ', 25);///* Note: The traditional JavaScript method implements inheritance * boy.prototype=new person ( ' John Doe '); * var b=new boy (' Male ', 25); */alert (' Name: ' +b.name+ '--Gender: ' +b.sex+ '--id: ' +b.id+ '--Age: ' +b.age ');
Example Results: