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