尽管启用了实验性 js,但 ECMA 6 不起作用 [英] ECMA 6 Not working although experimental js is enabled

查看:21
本文介绍了尽管启用了实验性 js,但 ECMA 6 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有最新的 Chrome 版本(45 和版本 47 的 Chrome Canary),两者都启用了实验性 Javascript 标志.我想使用 ECMA6,但它不起作用.我不知道为什么.是否有任何技巧或其他标志也必须启用?

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?

ECMA6 的每个保留字(如导入、类或其他)都会在 Chrome 45 中引发未捕获的语法错误:意外的保留字"错误,在 Chrome Canary 中引发未捕获的语法错误:意外的令牌导入"错误.

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.

我将不胜感激.而且,因为我几个月前问过这个问题,但没有得到任何答案,但可能重复"这个 使用 ECMAScript 6 ,它不是.它不能解决我的问题.

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.

谢谢.

--- 编辑---我想使用模块,因为与使用 Require 或 Common 相比,我更喜欢 ecma6 模块.而且我也喜欢类的语法糖,代码看起来更好:)

--- 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 :)

推荐答案

任何浏览器均不支持模块.您将需要使用转译器,例如 Traceur巴别塔.查看以下内容之一以帮助您入门:

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/

截至目前,您可以看到大多数浏览器本身还不支持类.但是,如果您使用的是 Babel 或 Traceur,则不必担心.

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.

这篇关于尽管启用了实验性 js,但 ECMA 6 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆