In jquery, there's this way
var obj = {};
$.data (obj,' name ', ' Jake '); Console.info ($.data (obj,' name ')); Console.info (obj);
Output results
So, $.data (), in which there are three parameters, is assigned, there are two parameters is the value, the consistent jquery style.
Here, imitate.
var$data = (function(){ varexpando = ' jQuery ' +string (Math.random ()). Replace (/\d/g, "); functionGetCache (cache) {returncache[expando]=cache[expando]| |{}; } functionSetValue (obj,name,value) {Obj[name]=value; } functionGetValue (obj,name) {returnObj[name]; } varData=function(cache,nameagr,valuearg) {varobj =GetCache (cache); //there is a third parameter indicating that the value is assigned if(valuearg&&valuearg.length>0) {setValue (OBJ,NAMEAGR,VALUEARG); }Else{//No third parameter indicates a value returnGetValue (OBJ,NAMEAGR); } } returndata; })(); varObj2 = {}; $data (Obj2,' Name ', ' Jake '); $data (Obj2,' Age ', ' 12 '); Console.log ($data (Obj2,' Name ')); Console.log (OBJ2);
Results
The two methods are imitated.
Original
Http://www.cnblogs.com/ellisonDon/archive/2012/08/12/2635316.html
Data that mimics jquery