.then 是否受 Internet Explorer 支持?

is .then supported by Internet Explorer?

我了解到 IE 不支持 promises,但是我有带有 .then 的遗留代码,在 IE 上似乎 运行 没问题。

怎么会像我理解的那样.then = promises?

谢谢

Promise.prototype.then() 方法 returns 一个 Promise。该方法仍然不支持IE浏览器。您可以查看 Browser compatibility.

要在 IE 11 浏览器中使用 Promise and Then 方法,您可以使用第 3 方承诺库(如 Bluebird)或 Babel 转译器将 ES6 代码转换为 ES5 代码。请参考以下示例代码:

<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.4/bluebird.min.js"></script> 

<script>
    (function (global, factory) {
        if (typeof define === "function" && define.amd) {
            define([], factory);
        } else if (typeof exports !== "undefined") {
            factory();
        } else {
            var mod = {
                exports: {}
            };
            factory();
            global.repl = mod.exports;
        }
    })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function () {
        "use strict";

        var myFirstPromise = new Promise(function (resolve, reject) {
            // We call resolve(...) when what we were doing asynchronously was successful, and reject(...) when it failed.
            // In this example, we use setTimeout(...) to simulate async code. 
            // In reality, you will probably be using something like XHR or an HTML5 API.
            setTimeout(function () {
                resolve("Success!"); // Yay! Everything went well!
            }, 250);
        });
        myFirstPromise.then(function (successMessage) {
            // successMessage is whatever we passed in the resolve(...) function above.
            // It doesn't have to be a string, but if it is only a succeed message, it probably will be.
            console.log("Yay! " + successMessage);
        });
    });
</script>

IE浏览器输出:

编辑:

deferred.then()方法支持IE浏览器。也许您正在使用 deferred.then 方法。