Chrome 浏览器支持Javascript中的类语法[重复]

fnvucqvd  于 2023-04-27  发布在  Go
关注(0)|答案(2)|浏览(94)

此问题已在此处有答案

ES6 classes don't work on Chrome 47(1个答案)
7年前关闭。
下面的语法,

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: Unexpected token class(…)
chrome version insalled 47.0.2526.80 m
Firefox版本安装44.0a2 (2015-12-12)
哪个版本的浏览器支持classextends关键字?

clj7thdc

clj7thdc1#

1.你可以使用一个javascript到javascript的编译器,比如Babel,将ES6 javascript编译成ES5代码。它涵盖了ES6的大部分特性。
1.请查看https://kangax.github.io/compat-table/es6/中的ES6特性表,以及不同浏览器对它们的支持程度。

vltsax25

vltsax252#

截至2015年12月14日:

  • Chrome浏览器42.0
  • Firefox Gecko Nightly Build
  • 边缘13
  • Safari 9

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes
https://nightly.mozilla.org/

  • Javascript规格:*

http://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions
https://tc39.es/ecma262/multipage/ecmascript-language-functions-and-classes.html#sec-class-definitions
http://jshint.com/docs/options/#esnext

相关问题