1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>functionModule</title> 6 </head> 7 <body> 8 9 <script type="text/javascript"> 10 11 //建造者模式 12 //1.产出的东西是房子 13 //2.baogongtou调用工人进行开工 而且他要清楚工人们具体的某一个大项目 14 //3.gongren是盖房子的 工人可以建卧室 客厅 厨房 15 //4.包工头只是一个接口而已,他不干活 他只对外说我能盖房子 16 17 //房子 18 function Fangzi(){ 19 this.woshi=""; 20 this.keting=""; 21 this.chufang=""; 22 } 23 24 //包工头 25 function Baogongtou(){ 26 this.gaifangzi=function(gongren){ 27 gongren.jian_woshi(); 28 gongren.jian_keting(); 29 gongren.jian_chufang(); 30 } 31 } 32 33 34 //工人 35 function Gongren(){ 36 this.jian_woshi=function(){ 37 console.log("卧室盖好了"); 38 }; 39 this.jian_keting=function(){ 40 console.log("客厅盖好了"); 41 }; 42 this.jian_chufang=function(){ 43 console.log("厨房盖好了"); 44 }; 45 46 this.jiaogong=function(){ 47 48 var __fangzi= new Fangzi(); 49 50 __fangzi.woshi="ok"; 51 __fangzi.keting="ok"; 52 __fangzi.chufang="ok"; 53 54 return __fangzi; 55 56 }; 57 } 58 59 60 var gongren= new Gongren(); 61 var baogongrou= new Baogongtou(); 62 baogongrou.gaifangzi(gongren); 63 64 var myfangzi =gongren.jiaogong(); 65 66 console.log(myfangzi); 67 68 </script> 69 </body> 70 </html>