Class是一个特殊的函数,用来生产对象,实现继承。
静态方法:
直接通过类来调用,这就称为“静态方法”
class Foo {static classMethod() {return 'hello';}}Foo.classMethod() // 'hello'var foo = new Foo();foo.classMethod()
静态属性:
静态属性指的是 Class 本身的属性
// 老写法class Foo {// ...}Foo.prop = 1;// 新写法class Foo {static prop = 1;}
实例属性:
class IncreasingCounter {constructor() {this._count = 0;}get value() {console.log('Getting the current value!');return this._count;}increment() {this._count++;}}
也可以:
class IncreasingCounter {_count = 0;get value() {console.log('Getting the current value!');return this._count;}increment() {this._count++;}}
