ECMA 6虽然启用了实验性js,但不起作用 [英] ECMA 6 Not working although experimental js is enabled
问题描述
我有最新的Chrome版本,启用了实验Javascript标志。我想使用ECMA6,但它不工作。我不知道为什么有没有任何技巧或其他标志也必须启用? ECMA6的每个保留字(如导入,类或其他)会引发未捕获的语法错误:意外的保留字错误。
我将非常感谢任何帮助。而且,因为我几个月前问这个问题,而是没有得到任何答案,但使用ECMAScript 6 a>,不是。这不能解决我的问题。
谢谢。
---编辑---
我想使用模块,因为我喜欢更多的ecma6模块,而不是使用Require或Common。而且我也喜欢类的糖语法,代码看起来更好:)
我正在运行Chrome 45(及其更新版本),还有Chrome Canary(在版本47中)。他们都启用了启用实验Javascript标志。
- 编辑2 -
在Chrome Canary中,控制台中出现的错误不同的:未捕获的SyntaxError:意外的令牌导入,而在Chrome中它会抛出意外的保留字。
尚未在任何浏览器中本地支持。您将需要使用透明机,例如 Traceur 或 Babel 。查看以下其中一个以帮助您开始使用:
对于类,您可以使用这些本机,而无需经历一个透析器。您可以在此查看兼容性表,查看哪些浏览器今天支持本机:
https://kangax.github.io/compat-table/es6/
截至目前,您可以看出,大多数浏览器还没有支持本地的类。但是,如果您使用的是Babel或Traceur,那不应该是一个问题。
First of all... excuse my bad english.
I have the latest Chrome version, 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.
I will appreciate any help. And, because i ask 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 :) I'm running Chrome 45 (and its updated), and also Chrome Canary (which is in version 47). Both of them with the flag "Enable Experimental Javascript" enabled.
-- EDIT 2 -- In Chrome Canary, the error that appears in the console it's different: "Uncaught SyntaxError: Unexpected token import", while in Chrome it throws an "Unexpected reserved word".
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:
- Choose ES6 modules Today!
- ES6 In Depth: Using ES6 today with Babel and Broccoli
- Writing client-side ES6 with webpack
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.
这篇关于ECMA 6虽然启用了实验性js,但不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!