ES6

ES6 指 ECMA2015,这里泛指此后的规范,JavaScript 新特性正在一个一个的向我们走来。

traceur-compileropen in new window

BigInt

typeof 1n === "bigint"; // true
typeof BigInt("1") === "bigint"; // true
typeof Object(1n) === "object"; // true
0n === 0; // false
0n == 0; // true
const expected = 4n / 2n; // ↪ 2n
const rounded = 5n / 2n; // ↪ 2n, not 2.5n

Class

Class 本质还是 function。

class Foo {}

typeof Foo; // 'function'

class 声明的类只能通过 new 实例化,不能像构造函数一般直接调用。

Promise

Promise 是异步编码风格的解决方案。

生成器

生成器函数是一个带星号函数,而且是可以暂停执行和恢复执行的。

async

async/await 构建在生成器和 Promise 的基础之上,进一步优化了 Promise 大量的 then 回调风格,以同步方式 code 异步代码。

小结

  1. Class 和构造函数的区别
  2. Proxy 和 Reflect