Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 classes don't work on Chrome 47

Google Chrome claims to support ES6 classes since version 42, but it gives Uncaught SyntaxError: Unexpected token class(…) when i run the simple code from below in the console:

class Polygon {
  constructor(height, width) {
    this.name = 'Polygon';
    this.height = height;
    this.width = width;
  }

Firefox also doesn't work. Microsoft Edge works just fine. Is this normal?

like image 912
Vahid Amiri Avatar asked Dec 11 '15 19:12

Vahid Amiri


People also ask

How do I enable ES6 in Chrome?

In Chrome, most of the ES6 features are hidden behind a flag called "Experimental JavaScript features". Visit chrome://flags/#enable-javascript-harmony , enable this flag, restart Chrome and you will get many new features.

Is ES6 compatible with Chrome?

ECMAScript 2015 (ES6) is Fully Supported on Google Chrome 53.

Can we run ES6 in browser?

ES6 modules can be used without bundling out of the box on most modern browsers. The latest versions of Chrome, Firefox, Edge, Safari and mobile versions of them all support it out of the box. Other than Internet Explorer, most popular browsers can load ES6 modules on their own.

What ECMAScript does chrome use?

Note: ECMAScript 5 is Fully Supported on Google Chrome 56.


1 Answers

Are you in "use strict" mode?

ES6 classes solve this by providing JavaScript a clean, standardized syntax for classes. This new syntax is available in Chrome 42 for JavaScript written in strict mode.

like image 127
dsdenes Avatar answered Sep 21 '22 02:09

dsdenes