What is the use of Ext.define in Ext.js4.2.1
This article is to share with you about the use of Ext.define in Ext.js4.2.1. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
One: description
Define (String className, Object data, Function createdFn): Ext.Base
The define method accepts up to three parameters, className (class name), data (Object object), and createdFn (callback function).
Often used to define a class, override a class, or extend the properties or methods of a class.
Two: method explanation
Ext.define ("Person", {
Config: {
Name:''
Age: 0
}
Say: function (msg) {
Ext.Msg.alert (this.Name + "Says:", msg)
}
Constructor: function (config) {
This.initConfig (config)
}
});
Ext.define ("Animal", {
Sing: function () {
Ext.Msg.alert ("Sing", "lalalalalallalalal")
}
});
Ext.define ("MyApp.Developer", {
Extend: 'Person'
Mixins: {
CanSing: 'Animal'
}
Alias: 'Developer'
Requires: []
Config: {}
Coding: function (code) {
Ext.Msg.alert (this.Name + "coding", code)
}
Statics: {
Test: function (msg) {
Return "Test" + msg
}
}
});
Var Alex = Ext.create ("Developer", {
Name: "Alex"
Age: 26
});
Alex.setAge (33)
Alert (Alex.getAge ())
Alert (MyApp.Developer.test ('any Wayside'))
Alex.Sing ()
Alex.Coding ("int iTunes 1;")
1.config
Configuration item. This.initConfig (config) is called to initialize the configuration item. Four functions are automatically generated for each configuration item: get,set,reset,apply
2.extend
Used for inheritance of classes
3.mixins
Class, similar to Ext.override. But it will not overwrite the original functions like override.
4.alias
Alias of the class
5.requires
ExtJS4's requires is a new mechanism, which mainly implements asynchronous loading mechanism. In this way, the corresponding js file will not be loaded without clicking the corresponding button or option, which improves the loading speed and user waiting time.
The implementation of the requires mechanism uses an Ext.Loader.setConfig function to set the mapping directory that the file is looking for, and then uses Ext.require to load when the corresponding js file is needed.
6.statics
You can define static methods in a class
Three: other
1.Ext.apply (object,config, [defaults]): Object
The method contains three parameters, the first parameter is the target object to be copied, the second parameter is the copied source object, and the third parameter is optional, indicating that a default value is provided to the target object. It can be simply understood as copying the third parameter (if any) and the attributes in the second parameter to the first parameter object.
2.Ext.applyIf (object,config): Object
The function is the same as apply, except that properties that exist in both the target object and the source object are not copied
Thank you for reading! This is the end of this article on "what is the use of Ext.define in Ext.js4.2.1?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!