Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

javascript - ECMA 6 Not working although experimental js is enabled

I have the latest Chrome version (45 and also Chrome Canary which is in version 47), both with the Experimental Javascript flag enabled. I want to use ECMA6, but it doesn't work. I don't know why. Is there any trick or other flag that must be enabled too?

Every reserved word of ECMA6 (like import, class, or whatever) throws an "Uncaught SyntaxError: Unexpected reserved word" error in Chrome 45 and an "Uncaught SyntaxError: Unexpected token import" error in Chrome Canary.

I will appreciate any help. And, because I asked this a few months ago without getting any answer but "possible duplicate" of this Using ECMAScript 6 , it is not. It does not solve my problem.

Thanks.

--- EDIT --- I want to use modules, since I like more the ecma6 modules than using Require or Common. And I also like the sugar syntax of classes, code looks better :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Modules are not yet natively supported in any browser. You will need to use a transpiler such as Traceur or Babel. Take a look at one of the following to help you get started:

As for classes, you may be able to use these natively without having to go through a transpiler. You can check the compatibility table here to see which browsers support classes natively today:

https://kangax.github.io/compat-table/es6/

As of right now, you can see that the majority of browsers do not yet support classes natively. However, if you are using Babel or Traceur, that shouldn't be a concern.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...