updated to 101 (New length ).Similarly, if you modify the Length attribute of an array, the elements that are no longer part of the array will be deleted.All objects in JScript support the "expando" attribute or those attributes that can be dynamically added or deleted at runtime.These attributes can contain any number name.If the property name is a simple identifier For example, VAR myobj = new object ();// Add two
This data is, of course, accessed through attributes, but what about multiple attributes? , do you want to define multiple properties? , what is the name of the property? Will it conflict with other attributes?
In JQuery, private data extended for DOM objects can be represented by an object, and multiple data is represented by multiple properties of the object. To be able to find this extended data object through a DOM object without conflict with other existing attributes, the
JQ has a method of data that binds the DOM elements to the relevant information. When an event is bound to the DOM using a JQ method, a corresponding time list is generated
See the example below (see Firefox for object Support Tosource ())
Copy Code code as follows:
Data is an element that binds to the
The data source is the cache object
When the element binds the data, an attribute is added to the element jqueryxxx xxx is the timestamp of the execution JQ
Here's to say, there'
objects to solve the memory leakage problem of Some browsers. In earlier versions of IE, GC cannot be correctly processed when circular references occur between DOM and JS objects. See Understanding and Solving Internet Explorer Leak Patterns. As for the COM object, this problem is bypassed because the object element does not have data.Copy codeThe Code is as follows:Data: function (elem, name, data, pvt ){// If it belongs to the element defined in noDataIf (! JQuery. acceptData (elem )){Return
Document object and the Window object are assigned a UUID. The UUID's property name is a random custom attribute, "JQuery" + (new Date ()). GetTime (), the value is an integer and is incremented from zero. But the UUID is always attached to an object, if that object is window, it is not a global pollution, so the jquery inside determines that it is a Window object, mapped to an empty object called Windowdata, and then the UUID added above it. With the UUID, when we first access the caching syst
property, "jQuery" + (new Date (). getTime (). The value is an integer and increases progressively from zero. However, the UUID is always attached to an object. If the object is a window, isn't it a global pollution? Therefore, when jQuery internally determines that it is a window object, it is mapped to an empty object called windowData, add the UUID to it. With UUID, when we access the cache system for the first time, an empty object (cache body) will be opened in the $. cache object for stor
Data Analysis of jQuery 3.0 and jquery Analysis
JQuery 3.0 was officially released in June 9, and 3.0 is also known as the next generation of jQuery. This version has been released for beta (October,) and candidate () since ). It's not easy along the way.
Document directory
I. Data Analysis
Data in jQuery 3.0 is used internally and is defined as a "class ". A total of two objects are created, datemediv and dataUser. Data has one object attribute (expando
pairs and becomes an empty object, jQuery will start from $. delete this object from the cache and remove the UUID from the target object.
The Code is as follows:
// JQuery1.2.3Var expando = "jQuery" + (new Date (). getTime (), uuid = 0, windowData = {};JQuery. extend ({Cache :{},Data: function (elem, name, data ){Elem = window? WindowData: elem; // special processing of window objectsVar id = elem [expando
property, "jQuery" + (new Date (). getTime (). The value is an integer and increases progressively from zero. However, the UUID is always attached to an object. If the object is a window, isn't it a global pollution? Therefore, when jQuery internally determines that it is a window object, it is mapped to an empty object called windowData, add the UUID to it. With UUID, when we access the cache system for the first time, an empty object (cache body) will be opened in the $. cache object for stor
// used to track events that have never been used and optimize jQuery. event. global [type] = true ;}}};
Note that objects and arrays are referenced! For example, the code that saves event data to the cache:
handlers = events[ type ] = [];if ( selector ) { handlers.splice( handlers.delegateCount++, 0, handleObj );} else { handlers.push( handleObj );}
If handlers is changed, events [type] will change at the same time.
Datatev is the object for managing cache:
The job is to create an attribute
expression (while) at the beginning of the loop, tests the expression at the end of the loop (Do/while), operates on each property of the object (For/in), and loops (for) controlled by the counter. such as: For...in loop (1) Traversal object properties: var myObject = new Object (); Myobject.name = "James"; Myobject.age = "22"; Myobject.phone = "555 1234";//enumeration (looping) All properties of the object for (prop in myObject) {//Traverse MyObject All properties (
then from the DOM element The attached property is removed and output.
Because we do not attach objects directly to the DOM element, given the problem of IE6, IE7 garbage Collection on object references on DOM element, we use global cache and append a UID to the DOM element.
The implementation method is as follows:
$ = function () {
var expando = "JQuery" + ("6" + mathrandom ()) Replace (/\d/g, ");
var globalcache = {};
var uuid = 0;
For jQuery'sData Cache, I believe everyone will not be unfamiliar,JQuery Cache SystemNot only usedDOM Element,Animation and eventAnd so on. Therefore, in actual applications, we often need to cache some data for elements, which are often closely related to DOM elements. Because DOM elements (nodes) are also objects, we can directly extend the attributes of DOM elements. However, adding custom attributes and excessive data to DOM elements may causeMemory leakageSo we should try to avoid this. The
jquery1.4 jquery1.4 Download The jQuery1.4 is used here, why use 1.4 because 1.4 many features are relatively easy to analyze without adding them. The implementation of this data is extended in the jquery static function, and we usually ($ (' #data '). Data (' Tudou ', ' abc ') calls the data on the jquery prototype, and the data on the prototype is then called under jquery static Data method implementation. Jquery.extend ({cache:{},expando:expando,//thefollowingelementsthrow Uncatchableexcepti
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.