[js] window.onload を await したくなった

に公開

^.,.^ < Hey! 青色きつねです。
なんとなくwindow.onload待っとくかと思い立つ事ってありますよね。
asyncの中ならawaitできます。

ソース

await new Promise((resolve) => {
  let load = async (event) => {
    window.removeEventListener("load", load);
    resolve(event);
  };
  window.addEventListener("load", load);
});

Social

https://github.com/xoFeulB
https://twitter.com/xoFeulB
https://bsky.app/profile/xofeulb.bluefox.tech

Discussion