Bridging mode
1. While the system changes along multiple dimensions, it does not increase its complexity to achieve decoupling
2. The main feature: decoupling the implementation layer (such as an element-bound event) from the abstraction layer (such as the Decorated page UI logic), allowing the two parts to change independently
3. Avoid changes in demand resulting in changes in the object, reflecting the object-oriented development and modification of the closure principle
Demo instance: Create an object bridging method that implements the function of the object extension approach
Extract common denominator (abstraction layer)
1 function (NAME,FN) {2 This [Name] = fn; 3 }
Creating a class and instantiating an object (Implementation layer)
1 function Box (x, Y, z) {2 this. x=x; 3 this. y=y; 4 this. z=Z; 5 }6 7 var box=new box (20,10,10);
Expanding methods for objects (bridging methods)
1 Box.addmethod ("init",function() {2 console.log ("box length:" + this.x+ ", Width:" +this. y+ ", height is:" +this. z); 3 }); 4 Box.addmethod ("getwidth",function() {5 console.log (this. Y ); 6 });
Test code
1 box.init (); 2 Box.getwidth ();
Console display
javascript-Bridging mode