JS design mode Note 4, bridging mode

Source: Internet
Author: User

1    2 3     //Bridging mode is the function of separating the implementation part from the abstract part so that the two can change independently. 4     varsingleton=function(FN) {5         varresult;6         return function(){7             returnresult| | (Result=fn.apply ( This, arguments));8         }9     }Ten     varCreatemask=singleton (function(){ One         returnDocument.body.appendChild (document.createelement ("div")); A     }); -     //Singleton is the abstract part, and Createmask is the realization part, they are independent of each other. -     //2, another common example is the implementation of the Foreach function, which is used to iterate over an array.  theForeach=function(ARY,FN) { -          for(vari=0,l=ary.length;i<l;i++){ -             varC=Ary[i]; -             if(Fn.call (c,i,c) = = =false){ +                 return false; -             } +         } A     } at  -ForEach ([+],function(i,n) { -Alert (n*2); -     }) -ForEach ([+],function(i,n) { -Alert (n*3); in     }) -  to</script>

JS design mode Note 4, bridging mode

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.