Search code examples
internet-explorerdeferred

is .then supported by Internet Explorer?


I have read that IE does not support promises, however I have legacy code with .then which seems to run fine on IE.

How can this be as my understanding is .then = promises?

Thanks


Solution

  • The Promise.prototype.then() method returns a Promise. This method still doesn't support IE browser. You could check the Browser compatibility.

    To use the Promise and Then method in IE 11 browser, you can use 3rd party promise library (like Bluebird) or Babel transpiler to convert the ES6 code to ES5 code. Please refer the following sample code:

    <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>
    

    The output in IE browser:

    enter image description here

    Edit:

    The deferred.then() method support IE browser. Perhaps you are using the deferred.then method.