What is Ext.Class in Ext.js4.2.1
Editor to share with you what Ext.Class is in Ext.js4.2.1, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
One: description
Ext.Class is a low-level factory class that is used by Ext.ClassManager and generally does not use Ext.Class directly, except when creating an anonymous class.
If you want to create a class, use Ext.define, which is an alias for Ext.ClassManager.create.
Ext.Class is a factory class, not a parent of any class. The base class of all classes is Ext.Base
Two: Config
1.alias abbreviation / alias
Such as:
Ext.define ('MyApp.CoolPanel', {
Extend: 'Ext.panel.Panel'
Alias: ['widget.coolpanel']
Title: 'Yeahworth'
});
/ / Using Ext.create
Ext.create ('widget.coolpanel')
/ / Using the shorthand for defining widgets by xtype
Ext.widget ('panel', {
Items: [
{xtype: 'coolpanel', html:' Foo'}
{xtype: 'coolpanel', html:' Bar'}
]
});
2.alternateClassName optional name
Such as:
Ext.define ('Developer', {
AlternateClassName: ['Coder',' Hacker']
Code: function (msg) {
Alert ('Typing...' + msg)
}
});
Var joe = Ext.create ('Developer')
Joe.code ('stackoverflow')
Var rms = Ext.create ('Hacker')
Rms.code ('hack hack')
3.config has configuration parameters with default values
Such as:
Ext.define ('SmartPhone', {
Config: {
HasTouchScreen: false
OperatingSystem: 'Other'
Price: 500
}
Constructor: function (cfg) {
This.initConfig (cfg)
}
});
Var iPhone = new SmartPhone ({
HasTouchScreen: true
OperatingSystem: 'iOS'
});
IPhone.getPrice () / 500
IPhone.getOperatingSystem (); / / 'iOS'
IPhone.getHasTouchScreen (); / / true
4.extend inheritance, the parent of the current class
Such as:
Ext.define ('Person', {
Say: function (text) {alert (text);}
});
Ext.define ('Developer', {
Extend: 'Person'
Say: function (text) {this.callParent (["print" + text]);}
});
5.inheritableStatics inheritable static methods
Static methods that cannot be inherited by 6.statics
Such as:
Ext.define ('Computer', {
Statics: {
Factory: function (brand) {
/ / 'this' in static methods refer to the class itself
Return new this (brand)
}
}
Constructor: function () {...}
});
Var dellComputer = Computer.factory ('Dell')
7.mixins mixes other classes into the current class
Such as:
Ext.define ('CanSing', {
Sing: function () {
Alert ("I'm on the highway to hell...")
}
});
Ext.define ('Musician', {
Mixins: ['CanSing']
})
At this point, Musician will have a method of sing, which comes from the CanSing class mixin.
If Musician itself already has a sing method, you should do the following:
Ext.define ('Musician', {
Mixins: {
CanSing: 'CanSing'
}
Sing: function () {
/ / delegate singing operation to mixin
This.mixins.canSing.sing.call (this)
}
})
8.requires the class that needs to be loaded before the current class is loaded, similar to import
Such as:
Ext.define ('Mother', {
Requires: ['Child']
GiveBirth: function () {
/ / we can be sure that child class is available.
Return new Child ()
}
});
9.singleton singleton mode
The class that 10.uses loads with the current class is not a required class
Such as:
Ext.define ('Mother', {
Uses: ['Child']
GiveBirth: function () {
/ / This code might, or might not work:
/ / return new Child ()
/ / Instead use Ext.create () to load the class at the spot if not loaded already:
Return Ext.create ('Child')
}
});
The above is all the content of this article "what is Ext.Class in Ext.js4.2.1?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!