Ext4 does not explain what ext4 is. It can read thisArticleYou must know.
Download the ext4 compressed package, dozens of megabytes a day. This is not written by humans.
But what I want to say is: the author intentionally makes it so big that there is not so much single source code, about 3 MB.
It is not easy to interpret the source code of Ext.
But I believe many people need it!
I hope this source code explanation will benefit you a lot.
Of course, if you don't even know the basic JS syntax, give up,
It is not a JS tutorial.
Do not mark this article and read it later.
This means that you will not read it.
Sometimes, learning is forced.
But you can definitely read this article while listening to music.
Learning to find happiness in learning is a skill.
EXT 4 source code
Xcould/Text
Qq 1, 744257564
Please indicate the source when reprint: http://www.cnblogs.com/xuld/
Preparation: Download The ext4 compressed package. You can find Several folders and files: examples (example), Src (source code), ext-all-debug-w-comments.js (all with annotations)Code)
Because the official website can be updated at any time, this article is written by a specific version, and details the number of lines of code. In order to allow readers to read the source code synchronously, we provide the source code when writing this article.
Click here to download
This article explains are SRC files, rather than ext-all-debug-w-comments.js, mainly because the ext-all-debug-w-comments.js is too large, I use the editor card of the resistance.
I did not write any Chinese textbooks. I should not make a fuss about the typos.
Of course, if you find any errors, including incorrect characters, please point them out.
Ah ..
Some people complained that the text has not been started yet.
When reading an article, you 'd better open the ext source code at the same time and read it after comparison.
Start now...
Part 1 core/Core
Source code: Core/src/EXT. js
First l 1-14 (1st to 14th rows), you can find:
EXT is based on GPL Open Source-unless your stuff is also GPL open source, you must pay for it before you can use ext 4.
The author makes clear the goal of making money by commenting on the source code.
Then l 16-17
These two are document comments. @ Class indicates that ext is a class @ Singleton, indicating that this is a singleton mode class. That is to say, the following members are directly available for Ext, rather than Ext. prototype.
L 20
VaR global = This. This is the window. When the global function is executed, this points to the window.
[If you don't understand this, you can read my article: http://www.cnblogs.com/xuld/archive/2011/06/23/2087971.html]
L 21-23
There is nothing to say, that is, the definition of common variables.
L 24
Enumerablestest = {tostring: 1}
What is this?
For (var I in enumerablestest) {alert (I)}, the standard browser outputs "tostring" because tostring is already a custom member. So or in will traverse this member, while IE6 only recognizes the name but does not recognize the person. It does not output custom tostring members, including those of other systems. Therefore, in IE6, You need to determine whether tostring is defined.
L 27-30
Why does typeof ext = 'undefined' create Ext?
This is because the author considers that if ext or ext. js has been defined twice, it cannot directly overwrite the previous data.
L 31
Ext. Global = Global. Why? Save the global object.
This will not allowProgramIt's too dead, but the function of this library is extended.
L 33-37
See l 24
L 46
You can use Ext. enumerables to obtain or modify the traversal attributes.
L 57-80
This is a function Ext. Apply (object, config, defaults ),
It can be understood that if three parameters exist, the defaults member is first copied to the object.
Therefore, this function has two parameters:
Ext. Apply (object, config)
The function is to copy the config member to the object.
The copy method is the for in object, and members are assigned values one by one.
Of course, as l 24 said, if it is IE6, You need to manually check the custom attributes, instead of simply using for in.
The check method is hasownproperty.
L 82-85
Ext. buildsettings is used to store configurations. This is just a definition.
Of course, ext. Apply (..., ext. buildsettings ||{}) is used to prevent existing configurations from being overwritten.
You can use ext = {buildsettings: {...} to configure this library before launching Ext.
L 86
The next step is to expand ext itself.
L 91-92
Empty functions are very useful.
Ext. emptyfn is an interface. Define an empty function before implementation.
L 93
Basecssprefix CSS prefix
L100-114
Ext. applyif is equivalent to Ext. apply, but does not overwrite existing members.
In addition, it only has two parameters.
L 127-143
Ext. iterate traverses objects or arrays.
L 145
The author is confused. Why write separately? It is estimated that the next version will be merged.
L 155-214
Ext. Extend implement inheritance. If you do not understand the principle of inheritance, read my article: http://www.cnblogs.com/xuld/archive/2011/06/10/2077791.html
In addition, this function has been discarded because ext 4 has a complete class mechanism.
L 246-253
Ext. Override implements overload.
It is related to polymorphism.
Further analysis.
L 268-270
Ext. valuefrom is the default value.
If a parameter is not blank, this parameter is returned. Otherwise, the default value is returned.
Generally, when we need this effect | enough.
L 293-342
Ext. typeof return type
For common objects, typeof can be used to obtain the type, but typeof will always cheat us.
For example, typeof null = "object"
Typeof [] = "object"
What we really need is something that can normally report the object content.
So, of course, if typeof does not return an object, it will return.
Otherwise, how does one determine whether the object is determined by other methods?
Use object. Prototype. tostring to obtain the object description. According to this description, the type is obtained.
For example, new number (3)-> [object number], you can determine this is a number.
If nodetype exists, it indicates it is a node. Of course, no one can define this attribute on purpose.
L 358-360
Ext. isempty judge null undefined null string or Array
L 369-492
Ext. isxxx
Most of them will not be explained. There are just a few instructions:
Isprimitive primitive is not a common word. isprimitive determines whether a variable references a value.
For example:
VaR F = 1;
F. A = 2;
Alert (F. a); // output undefined
Such F is a common value type and does not include other attributes. Such variables are called isprimitive variables.
The isiterable array returns false.
L 504-552
Ext. Clone deep copy object. Do not use this function unless you are the author.
It is a big energy user.
L 558-572
Ext. getuniqueglobalnamespace oh, sorry, this is a private function of Ext. I have told you about it.
This function is used to generate a unique name. Of course, the prefix is extbox. The author also used the sandbox professional vocabulary, that is, objects can be secretly hidden in the box.
L 578-587
Ext. functionfactory: This is a good installation.
This code may scare a group of people.
ARGs is the first parameter except the parameter array.
Why not use ARGs [args. Length-1] instead of argS. Push?
Yes. I think the author thinks so.
ARGs memory is the code that defines ext = xxx.
Note that it creates a closure.
That is, the function returns a function, and the returned function creates an ext variable.
This is the so-called sandbox.
Function. Prototype. constructor. Apply (function. prototype, argS)
This sentence is equivalent to function. Apply (function. prototype, argS)
Equivalent to new function (ARGs [0], argS [1], argS [2]...)
L 596
Ext. type is the same as Ext. typeof.
Databases with historical burdens are tired.
The first part ends.
Want to repeat it?
Please.
The first part explains how to create ext and basic functions.
These functions will be prepared later.
Of course Ext. js alone is not good.
It took two hours to write this article. If you read the text for a longer time, I would like to admire it.
If I turn it off after a few eyes (not you, of course), I don't regret it.