javascript--Collection Class

Source: Internet
Author: User
Tags hasownproperty

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

Related Article

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.