1 /**2 * Created by Administrator on 2015/4/14.3 */4 functionSet () {5 This. Values = {};6 This. N = 0;7 This. add.apply ( This, arguments);8 }9Set.prototype = {TenAddfunction () { One for(vari = 0; i < arguments.length; i++) { A varval =Arguments[i]; - varstr =Set._v2s (val); - if(! This. Values.hasownproperty (str)) { the This. values[str] =Val; - This. n++; - } - } + return This; - }, +Removefunction () { A for(vari = 0; i < arguments.length; i++) { at varstr =Set._v2s (Arguments[i]); - if( This. Values.hasownproperty (str)) { - Delete This. Values[str]; - This. n--; - } - } in return This; - }, toContainsfunction(value) { + return This. Values.hasownproperty (Set._v2s (value)); - }, theSizefunction () { * return This. N; $ },Panax NotoginsengForeach:function(f, context) { - for(varSinch This. Values) { the if( This. Values.hasownproperty (s)) { +F.call (Context, This. Values[s]); A } the } + } - }; $set={ $ //This is an intrinsic function that connects with arbitrary JavaScript values and unique character channeling . -_v2s:function(val) { - Switch(val) { the CaseUndefinedreturn' U '; - Case NULL:returnN;Wuyi Case true:return' t '; the Case false:return' F '; - default:Switch(typeofval) { Wu Case' Number ':return' # ' +Val; - Case' String ':return' "' +Val; About default:return' @ ' +ObjectId (val); $ } - } - //A string is returned for any object - //for different character channeling, this function will return different character channeling A //multiple invocations for the same object, always returning the same character channeling + functionobjectId (o) { the varprop= "|**objectid**|"; - if(!O.hasownproperty (prop)) { $o[prop]=set._v2s.next++; the } the returnO[prop]; the }; the } - }; in the //set the initial value of theset._v2s.next=100;
javascript--Collection Class