function
condition(test){   return({         cat :function(){console.log('cat');},         dog :function(){console.log('dog');},         zhiqiang : function(){console.log('zhiqiang');}      }[test] || function(){console.log('我是默认值');}   )(); }
dcf(); //
我是默认值
dcf('dog'); // dog
 

 

如上面的代码,利用s对象的特点,直接取相应的属性执行

相关文章:

  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-09-23
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
相关资源
相似解决方案