❤ ES6-22 Class 的基本语法

59 阅读1分钟

❤ ES6-22 Class 的基本语法

类的由来

function Point(x, y) {
  this.x = x;
  this.y = y;
}

Point.prototype.toString = function () {
  return '(' + this.x + ', ' + this.y + ')';
};

var p = new Point(1, 2);

Point.prototype.constructor === Point // true

constructor() 方法

类的实例

实例属性的新写法

取值函数(getter)和存值函数(setter)

属性表达式

Class 表达式

const MyClass = class { /* ... */ };

静态方法

静态属性

私有方法和私有属性

早期解决方案

私有属性的正式写法

in 运算符

静态块

类的注意点

严格模式

不存在提升

name 属性

Generator 方法

this 的指向

new.target 属性