JS

javascript es6 + Promise IE11 간단히 지원

시연이아빠 2021. 6. 11. 10:12

IE11 에서 es6와 Promise까지 지원하고 싶다.

 

webpack 쓰면 되는거 알겠는데 그냥 간단히 빨리 지원하고싶다.

<!DOCTYPE html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <title>Title</title>
</head>
<body>

</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.12.1/polyfill.js"></script>

<script type="text/babel">
  alert(`dd`);

  function resolveAfter2Seconds() {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve('resolved');
      }, 1000);
    });
  }

  async function asyncCall() {
    console.log('calling');
    const result = await resolveAfter2Seconds();
    alert(result);
  }

  asyncCall();
</script>
</html>

1. html 파일에 babel, polyfill cdn을 넣는다.

2. es6 문법과 Promise 지원 확인한다.

 

IE11 쓰면 벌금 메겼으면 좋겠다.