1.举栗子

  1. <script>
  2. /* 自调函数 不需要调用,直接执行 2.0 */
  3. // (function(){
  4. // console.log("自调1.0")
  5. // })()
  6. (()=>{
  7. console.log("自调2.0")
  8. })()
  9. </script>

2.利用自调获取接口数据

  1. <script>
  2. (async function(){
  3. var data = await httpGetCat("日语");
  4. var id = data.playlists[0].id;
  5. var res = await httpGetDetail(id)
  6. console.log(res)
  7. })();
  8. </script>