javascript - 浏览器支持 Javascript 中的类语法

标签 javascript google-chrome firefox browser ecmascript-6

<分区>

下面的语法,

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


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



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

--

chrome 和 firefox 都不支持。

SyntaxError: 意外的 token 类(…)

已安装 chrome 版本 47.0.2526.80 m

安装的 firefox 版本 44.0a2 (2015-12-12)

哪个版本的浏览器支持 classextends 关键字?

最佳答案

  1. 您可以使用 javascript 到 javascript 的编译器(例如 Babel)将 ES6 javascript 编译成 ES5 代码。它涵盖了大部分 ES6 功能。

  2. 看看https://kangax.github.io/compat-table/es6/获取 ES6 功能表以及不同浏览器对它们的支持程度。

关于javascript - 浏览器支持 Javascript 中的类语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34258272/

相关文章:

javascript - 嵌入文档时不需要的页面边框

javascript - 使用 jquery 匹配更改时的输入值

google-chrome - 从扩展程序访问网页的 `window`/DOM/HTML

python - 使用 selenium/python 获取相对于视口(viewport)的元素位置

google-chrome - 语法错误 : missing = in const declaration Firefox 50

javascript - 如何将用户的 displayName 添加到 Firestore 数据库集合条目?

javascript - 如何在 Angular 4 中单击按钮时在不同窗口中显示 pdf 文件

caching - Chrome 不缓存图像/js/css

javascript - Ajax 请求在 Chrome 中成功,但在 Firefox 中失败

javascript - 为什么 document.getElementById 不能只被 Firefox 识别