<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                >[danger]promise傳的參數(resolve,reject)執行時機是異步還是同步的? 在 Promise 中,`resolve` 和 `reject` 函數的執行時機是異步的。 當創建一個 Promise 對象時,其中包含的執行器函數會立即執行。在執行器函數內部,可以調用 `resolve` 函數將 Promise 的狀態設置為已解決(fulfilled),或者調用 `reject` 函數將 Promise 的狀態設置為已拒絕(rejected)。但是,`resolve` 和 `reject` 函數的執行并不會立即觸發 `.then()` 或 `.catch()` 方法中的回調函數執行。 具體來說: - 當調用 `resolve(value)` 函數時,Promise 對象的狀態會從待定(pending)變為已解決(fulfilled),并且回調函數會被放入微任務隊列中,在當前執行棧執行完畢后執行。 - 當調用 `reject(reason)` 函數時,Promise 對象的狀態會從待定(pending)變為已拒絕(rejected),同樣的,回調函數會被放入微任務隊列中,在當前執行棧執行完畢后執行。 這種異步行為確保了 Promise 的執行結果可以正確地傳遞給下一個 `.then()` 或 `.catch()` 方法,并且不會阻塞主線程的執行。 示例: ```javascript function asyncFunc() { return new Promise(function(resolve, reject) { console.log('Promise executor'); setTimeout(function() { resolve('Async operation completed'); }, 1000); }); } console.log('Before promise'); asyncFunc() .then(function(result) { console.log(result); }); console.log('After promise'); // 輸出順序: // Before promise // Promise executor // After promise // Async operation completed ``` 在上述示例中,Promise 的執行器函數立即執行,并在內部使用 `setTimeout` 模擬了一個異步操作。可以看到,在主線程中,Promise 的創建和執行是同步的,但是 `.then()` 方法中的回調函數是異步執行的。這樣可以確保異步操作完成后再處理結果,而不會阻塞其他的代碼執行。 總結:Promise 中的 `resolve` 和 `reject` 函數的執行時機是異步的,它們會在當前執行棧執行完畢后,放入微任務隊列中等待執行。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看