From the library perspective, ext (a friend who likes Chinese can visit its Chinese site) is not much different from prototype jquery Yui, but it has its advantages, complete oo support, mature general-purpose widgets, and support themes, good scalability, fast update and release of new widgates,CommunityIt is also very lively. The most important thing is that I personally like it.
OpenSource codeTake a look at its structure: Start with core.
EXT = {version: '2. 0-beta1 '};
This lineCodeIs to define a variable Ext. Without var, it indicates that the author wants to define it as global. The right side of the equal sign is in JSON (JavaScript Object Notation) format and is equivalent to the following code:
EXT = new object ();
Ext. Version = '2. 0-beta1 ';
Window ["undefined"] = Window ["undefined"];
In this line of code, it must be noted that window is different from Ext. It is a built-in borwser object without code declaration. Unlike compiling languages such as C #, when an object exists in JS, We can modify its members at any time. There are two ways to access image members: vertex recognition (such as Ext. Version) and index ext ["version"]. Indexing seems troublesome, but it is actually flexible, and in some cases (such as the namespace override and other functions to be mentioned below) is irreplaceable. For example, traverse the members of an object (each item in the attribute set ). Undefined is available only in Versions later than IE (JS) 5.5. This method is cleverly compatible with earlier browsers. After understanding the access to members by the index method, let's take a look at the Ext. Apply method.
Ext. apply = function (O, C, defaults) {
If (defaults) {
// no "this" reference for friendly out of scope CILS
Ext. apply (O, defaults);
}< br> If (O & C & typeof c = 'object ') {
for (var p in c) {
O [p] = C [p];
}< BR >}< br> return O;
};
This is a key method. It is similar to the object in prototype. extend is the same (extend is not used here because it is used to inherit Ext. extend above), implements the object extension function, that is, the function of copying members from object C (if there is a default configuration, first from the default configuration extension ). Ext has this method, and then uses this method to expand itself. The following method is used for expansion:
(function () {var I = 100; alert (I )})()
This writing is a legendary anonymous function. The advantage is that the objects defined in the function are never accessible outside the function. In addition, this anonymous function cannot be accessed by other code, even if the names of objects are not easily contaminated (many errors in JS are caused by object naming conflicts ). Normally, function a () {var I = 100; alert (I)}; (); in this way, a object A is left behind (it becomes memory garbage when it is not used again ). Return to the ext object. It adds several important members to itself:
- Namespace: The namespace of JS is actually a pair of necklaces. If "A. B. C" is input, three objects are generated and linked. It must be noted that Ext. namespace ("A. B. C") will encounter an error because it points A to arguments internally, so that the generated object does not exist outside the namespace. In the futureArticleThe extended namespaces of ext are used to read and understand each of them one by one.
- Applyif (O, C) extends non-undefined members in Object C to O.
- Addbehaviors (o)
- ID () to generate a unique object ID,
- ExtendExtended functions, that is, type inheritance. This is a crucial member, and the type derivation in the entire framework is inseparable from its support.
- The $ of getdom and prototype is the same.
- Type
- Removenode
- Destroy
- Num
- Callback
- Combine
- Each
- Urldecode
- Urlencode
JS built-in types include object string function number Boolean array date
The following is ext's extension of the built-in object and its prototype.
- Function. Prototype
- Createcallback applies the current function to the specified object and returns a new function for Call and execution.
- Createdelegate also returns a new function. The difference will be elaborated in later sections.
- Defer
- Createsequence
- Createinterceptor
- String
- Escape escape 'and \ symbol
- The leftpad is similar to the C # padleft padright. When writing it on your own, you often forget to consider passing in an empty string, which will lead to an endless loop.
- Format string, similar to string. Format of C #
- String. Prototype
- Toggle exchanges two values to replace a three-value expression.
- Trim spaces in trim
- Number. Prototype. Constrain
- Indexof
- Remove
- Array
- Indexof
- Remove
- Date. Prototype. getelapsed get the number of milliseconds between the current time and the object
Continue reading ext to learn JavaScript (2) Core/EXT. Extend from inheritance