Search code examples
javascriptecmascript-6babeljsinternet-explorer-10ecmascript-5

Convert Javascripts for IE10


I need to convert this function to work with IE10. I thought to use Babel to convert the file from ES6 to ES5, but i dont know how to use correctly Babel, because Babel dont convert Promise. The script ES6 is this:

....

function readTextFile(file) {
    return new Promise(function (resolve, reject) {
        let rawFile = new XMLHttpRequest();
        rawFile.open("GET", file, false);
        rawFile.onreadystatechange = function () {
            if (rawFile.readyState === 4) {
                if (rawFile.status === 200 || rawFile.status === 0) {
                    allText = rawFile.responseText;
                    resolve(allText);
                }
            }
        };
        rawFile.send(null);
    });
}

.....

Thanks so much for your help and your time.


Solution

  • I fixed including this CDN in my HTML

    <script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=es2015%2CPromise%2CPromise.prototype.finally%2Ces2016"></script>