8

Opening a file named index.html with the following code on Firefox 43 renders the following error:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script>
    "use strict";
    class RangeIterator {}
    </script>
    </head>
    <body>
    </body>
    </html>

I see the following error in the console:

SyntaxError: class is a reserved identifier

Any idea why I'm getting that error?

Mulan
  • 129,518
  • 31
  • 228
  • 259
btelles
  • 5,390
  • 7
  • 46
  • 78
  • 2
    Quick tip: Use this table (https://kangax.github.io/compat-table/es6/) to check ES6 features compatibility in browsers, compilers, etc. – Inacio Schweller Dec 22 '15 at 05:29

2 Answers2

24

Classes aren't supported in Firefox version < 45 according to this

Joseph Young
  • 2,758
  • 12
  • 23
2

According to Can I Use ES6 classes support form 45 version of Firefox. if 45 version also throws same error like SyntaxError: class is a reserved identifier then its better to convert to ES5.

enter image description here


Babel is a JavaScript compiler. Use it to Transform ES6 to ES5 format BABEL JS (or) ES6Console.

ES2015 classes « Check the below Converted code from ES6 to ES5.

// ES6                              ES5
class Shape {                   "use strict";
  constructor(color) {
    this._color = color;        function _classCallCheck(instance, Constructor) {
                                  if (!(instance instanceof Constructor)) {
                                    throw new TypeError("Cannot call a class as a function");
  }                               }
}                               }
                                var Shape = function Shape(color) {
                                  _classCallCheck(this, Shape);
                                  this._color = color;
                                };

@See

Yash
  • 9,250
  • 2
  • 69
  • 74