1-Promise的状态修改

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let p = new Promise((resolve, reject) => {
        // 改变状态,
        // 1.调用resolve函数, 状态由pending => fulfilled/resolved(成功)
        // resolve("Ok");
        // 2.调用reject函数, 状态由pending => rejected(失败)
        // reject("Error");
        // 3.抛出错误,或者抛出错误的实例对象
        throw "出问题了!";
      });

      console.log(p);
    </script>
  </body>
</html>
posted @ 2022-01-02 16:33  问某完红  阅读(95)  评论(0编辑  收藏  举报