jquery Source notes-Data caching

Source: Internet
Author: User

Data data is designed to address memory leaks, and his theory is that when we store data on an object, we actually save all the data in a separate data object, and this object only provides an interface that can access its own data in its existing data object.

This is a simple data data
vardata = {};functionSet (obj,name,value) {//stores an attribute on an object as an interface for accessing dataObj.expando = 1; //initialize the object and store the data in the location provided by our interfaceData[obj.expando] ={} Data[obj.expando][name]=Value}functionGet (obj,name) {//The fact is that the expando on the object specifies its own data to be accessed in the data location.     returnData[obj.expando][name]}varObj2 ={};set (obj2,"Name", "Winder"); Console.log (Get (Obj2,"Name"))//WinderConsole.log (OBJ2)//Object {expando:1}Console.log (Data[1])//Object {name: "Winder"}

It is clear from the code that we are actually accessing objects that are 1 referenced in the data object, and how to find the location of the data is provided by an interface property stored on the object.

When we used him in jquery,

jquery Source notes-Data caching

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.