ECMAScript 2015 (6th Edition)是目前 ECMAScript 语言规范的标准。通常被称为"ES2015",在SpiderMonkey 中它规定了 JavaScript 的实现标准,SpiderMonkey 是一个 JavaScript 引擎,被广泛用于火狐浏览器等谋智的众多产品中。
"ES.next" 的第一份工作草案 (基于 ECMAScript 5.1) 发布于 2011 年 7 月 12 日,代号为 "ES.next" 或 "Harmony"。2014 年 8 月,ECMAScript 2015 草案规范停止增加新的功能,开始进入稳定期与 bug 修复阶段。最终,ECMA-262 Edition 6 于 2015 年 6 月 17 日由 ECMA 联合大会 (ECMA General Assembly) 作为标准正式发布。它同时也是国际工业标准 ISO/IEC 16262:2016。
你可以通过 ecma-international.org 免费下载规范的 PDF 和 HTML 版本。
es-discuss 是 ECMAScript 规范的讨论与反馈渠道。
Firefox 已经支持的特性
这里列出的功能已经在 Firefox 中支持;每个特性后面标注了具体实现的浏览器版本。
标准库
Array 对象的补充
Arrayiteration withfor...of(Firefox 13)Array.from()(Firefox 32)Array.of()(Firefox 25)Array.prototype.fill()(Firefox 31)Array.prototype.findIndex()(Firefox 25)Array.prototype.keys()(Firefox 28)Array.prototype.copyWithin()(Firefox 32)get Array[@@species](Firefox 48)
新的 Map 和 Set,以及 WeakMap 和 WeakSet 对象
Map(Firefox 13)Mapiteration withfor...of(Firefox 17)Map.prototype.forEach()(Firefox 25)Map.prototype.values()(Firefox 20)- Constructor argument:
new(Firefox 37)Map(null) - Monkey-patched
set()in Constructor (Firefox 37) get Map[@@species](Firefox 41)
Set(Firefox 13)Setiteration withfor...of(Firefox 17)Set.prototype.forEach()(Firefox 25)Set.prototype.values()(Firefox 24)- Constructor argument:
new(Firefox 37)Set(null) - Monkey-patched
add()in Constructor (Firefox 37) get Set[@@species](Firefox 41)
WeakMap(Firefox 6)WeakMap.clear()(Firefox 20)- optional iterable argument in
WeakMapconstructor (Firefox 36) - Constructor argument:
new(Firefox 37)WeakMap(null) - Monkey-patched
set()in Constructor (Firefox 37)
WeakSet(Firefox 34)- Constructor argument:
new(Firefox 37)WeakSet(null) - Monkey-patched
add()in Constructor (Firefox 37)
- Constructor argument:
新的 Math 方法
Math.imul()(Firefox 20)Math.clz32()(Firefox 31)Math.fround()(Firefox 26)Math.cbrt()(Firefox 25)
Number 对象的补充
Number.isNaN()(Firefox 16)Number.isFinite()(Firefox 16)Number.isInteger()(Firefox 16)Number.parseInt()(Firefox 25)Number.parseFloat()(Firefox 25)Number.EPSILON(Firefox 25)Number.MIN_SAFE_INTEGER(Firefox 31)Number.isSafeInteger()(Firefox 32)
Object 对象的补充
Object.prototype.__proto__已经被标准化Object.is()(Firefox 22)Object.setPrototypeOf()(Firefox 31)Object.assign()(Firefox 34)Object.getOwnPropertySymbols()(Firefox 33)
Date 对象的补充
Date.prototypeis an ordinary object (Firefox 41)- generic
Date.prototype.toString(Firefox 41) Date.prototype[@@toPrimitive](Firefox 44)
新的 Promise 对象
Promise(Firefox 24, 在 Firefox 29 中默认启用)
新的 Reflect 对象
RegExp 对象的补充
RegExpsticky (y) flag (Firefox 38)RegExpunicode (u) flag (Firefox 46)- generic
RegExp.prototype.toString(Firefox 39) RegExp.prototype[@@match]()(Firefox 49)RegExp.prototype[@@replace]()(Firefox 49)RegExp.prototype[@@search]()(Firefox 49)RegExp.prototype[@@split]()(Firefox 49)get RegExp[@@species](Firefox 49)
String 对象的补充
String.fromCodePoint()(Firefox 29)String.prototype.codePointAt()(Firefox 29)String.prototype.endsWith()(Firefox 17)String.prototype.includes()(Firefox 40) (formerlyString.prototype.contains()(Firefox 17))String.prototype.repeat()(Firefox 24)String.prototype.normalize()(Firefox 31)String.raw()(Firefox 34)- \u{XXXXXX} Unicode code point escapes (Firefox 40)
新的 Symbol 对象
Symbol(Firefox 36)Symbol.iterator(Firefox 36)Symbol.for()- global Symbol registry (Firefox 36)Symbol.match(Firefox 40)Symbol.species(Firefox 41)Symbol.toPrimitive(Firefox 44)Symbol.prototype[@@toPrimitive](Firefox 44)Symbol.replace(Firefox 49)Symbol.search(Firefox 49)Symbol.split(Firefox 49)Symbol.hasInstance(Firefox 50)
Typed Arrays
Typed arrays 已经合并到 ECMAScript 2015 中,不再具有自己单独的规范。
ArrayBufferget ArrayBuffer[@@species](Firefox 48)DataViewInt8ArrayUint8ArrayUint8ClampedArrayInt16ArrayUint16ArrayInt32ArrayUint32ArrayFloat32ArrayFloat64Arrayget %TypedArray%[@@species](Firefox 48)
表达式和操作符
- Spread operator for arrays (Firefox 16)
- use
Symbol.iteratorproperty (Firefox 36)
- use
- Spread operator for function calls (Firefox 27)
- use
Symbol.iteratorproperty (Firefox 36)
- use
语句
for...of(Firefox 13)- works in terms of
.iterator()and.next()(Firefox 17) - use
"@@iterator"property (Firefox 27) - use
Symbol.iteratorproperty (Firefox 36)
- works in terms of
函数
- Rest parameters (Firefox 15)
- Default parameters (Firefox 15)
- Parameters without defaults after default parameters (Firefox 26)
- Destructured parameters with default value assignment (Firefox 41)
- Arrow functions (Firefox 22)
Generator function(Firefox 26)arguments[@@iterator](Firefox 46)
其他特性
- Binary and octal numeric literals (Firefox 25)
- Template strings (Firefox 34)
- Object initializer: shorthand property names (Firefox 33)
- Object initializer: computed property names (Firefox 34)
- Object initializer: shorthand method names (Firefox 34)
和 ES2015 规范不兼容的特性
Firefox (部分)实现了以下特性,但是与规范不兼容。原因有如下几个:Firefox 是依据 ES 6 规范的早期草案来实现,或者 Firefox 是作为实验性特性来实现,而当时与之类似的特性还没有被添加到 ES2015 规范中。
- Legacy iterators and generators (JS 1.7, Firefox 2)
- Destructuring assignment (JS 1.7, Firefox 2) (ES2015 compliance bug 1055984)
- bug 950547 implemented in Firefox 51)
- bug 950547 implemented in Firefox 51)