Read ext to learn JavaScript (1) Core/EXT. js

Source: Internet
Author: User

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:

    1. 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.
    2. Applyif (O, C) extends non-undefined members in Object C to O.
    3. Addbehaviors (o)
    4. ID () to generate a unique object ID,
    5. ExtendExtended functions, that is, type inheritance. This is a crucial member, and the type derivation in the entire framework is inseparable from its support.
    6. The $ of getdom and prototype is the same.
    7. Type
    8. Removenode
    9. Destroy
    10. Num
    11. Callback
    12. Combine
    13. Each
    14. Urldecode
    15. 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.

    1. Function. Prototype

      1. Createcallback applies the current function to the specified object and returns a new function for Call and execution.
      2. Createdelegate also returns a new function. The difference will be elaborated in later sections.
      3. Defer
      4. Createsequence
      5. Createinterceptor
    2. String
      1. Escape escape 'and \ symbol
      2. 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.
      3. Format string, similar to string. Format of C #
    3. String. Prototype
      1. Toggle exchanges two values to replace a three-value expression.
      2. Trim spaces in trim
    4. Number. Prototype. Constrain
      1. Indexof
      2. Remove
    5. Array
      1. Indexof
      2. Remove
    6. 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

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.