ES6课程不适用于Chrome 47 [英] ES6 classes don't work on Chrome 47

查看:117
本文介绍了ES6课程不适用于Chrome 47的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Chrome声称自版本42以来支持ES6类,但是它在$控制台中从下面运行简单的代码时,会导致 Uncaught SyntaxError:意外的令牌类(...)

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也无效。微软边缘工作很好。这是正常吗?

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

推荐答案

您是否在使用严格模式?

Are you in "use strict" mode?


ES6类通过为类提供一个干净,标准化的语法来解决这个问题。这种新语法在Chrome 42中可用于以严格模式编写的JavaScript。

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.

这篇关于ES6课程不适用于Chrome 47的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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