IE11 gives SCRIPT1002 error when class definition in javascript

I have some problems with IE11 and the static javascript class that I wrote.

The error I am getting is:

SCRIPT1002: Syntax error rgmui.box.js (6,1)

Which indicates:

// ===========================================
// RGMUI BOX
// Static class

class RgMuiBox {
^

So, I assume that I define this class wrong? What is the right way to do this?

I found a SO post that seems to indicate that the problem is ES5 vs ES6 - and I believe IE11 does not support ES6?

To be complete, this is what I have (simplified):

class RgMuiBox {
    static method1() {
    // .. code ..
    }
}

Thank!

+14
source share
3 answers

Hate to resume such an old problem, but it still shows good results, so I will add what I learned:

, @Mikey @REJH , IE11.

, , Babel, -, IE11.

+19

@ . IE11 , ES6: https://kangax.imtqy.com/compat-table/es6/

class RgMuiBox {
    static method1() {
    // .. code ..
    }
}

, , :

var RgMuiBox = {};
  RgMuiBox.method = function() {
    // ....
  }

, - , . , !

+7

var _createClass = (function () {
    function defineProperties(target, props) {
        for (var i = 0; i < props.length; i++) {
            var descriptor = props[i];
            descriptor.enumerable = descriptor.enumerable || false;
            descriptor.configurable = true;
            if ("value" in descriptor) descriptor.writable = true;
            Object.defineProperty(target, descriptor.key, descriptor);
        }
    }
    return function (Constructor, protoProps, staticProps) {
        if (protoProps) defineProperties(Constructor.prototype, protoProps);
        if (staticProps) defineProperties(Constructor, staticProps);
        return Constructor;
    };
})();

function _classCallCheck(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}

var StaticClass = (function () {
    function StaticClass() {
        _classCallCheck(this, StaticClass);
    }

    _createClass(StaticClass, null, [{
        key: "method1",
        value: function method1() {
            // .. code ..
        }
    }]);

    return StaticClass;
 })();
0

All Articles