1 <script type="text/javascript"> 2 //适配器模式 3 function ada(str){ 4 config = { 5 'type1':{name:'jack'}, 6 'type2':{name:'longze'} 7 }; 8 9 var currentObj = eval('config.'+str); 10 if(currentObj){ 11 alert(currentObj.name); 12 }else{ 13 alert('未找到匹配类型:'+str); 14 } 15 16 } 17 18 ada('type3'); 19 </script>