jQuery源碼筆記——資料緩衝

來源:互聯網
上載者:User

標籤:style   blog   io   color   ar   sp   資料   div   on   

資料資料是為瞭解決記憶體泄露,他的原理是,當我們將資料存放區到一個對象上面,實際上是將所有的資料存到一個單獨的資料對象裡,而這個對象只提供一個介面,這個介面可以訪問自己存在資料對象裡自己的資料。

這是一個簡單的資料資料
var data = {};function set(obj,name,value){    //在對象上儲存一個屬性,用作訪問資料的介面    obj.expando = 1;    //初始化對象,並在我們介面所提供的位置存放資料    data[obj.expando] = {}    data[obj.expando][name] =  value}function get(obj,name){    //實際就是通過對象上的expando指定在資料中位置去訪問的自己的資料。    return data[obj.expando][name]}var obj2 = {};set(obj2,"name","winder");console.log(get(obj2,"name")) //winderconsole.log(obj2) // Object { expando: 1}console.log(data[1]) // Object { name: "winder" }

由代碼可以很清楚看到,我們實際訪問的是資料對象中,1引用的對象;而如何找到資料的位置,則由儲存在對象上的一個介面屬性提供。

當我們把他運用在jQuery中

jQuery源碼筆記——資料緩衝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.