https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Classes
class StaticMethodCall {
static staticMethod() {
return 'Static method has been called';
}
static anotherStaticMethod() {
return this.staticMethod() + ' from another static method';
}
}
StaticMethodCall.staticMethod();
// 静态方法已被调用
StaticMethodCall.anotherStaticMethod();
// 另一个静态方法已被调用
// 类声明是定义类的一种方式,就像下面这样,使用 class 关键字后跟一个类名(这里是 Polygon),就可以定义一个类。
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
// 提升 : 函数声明和类声明之间的一个重要区别是函数声明是hoisted,类声明不会。
// 你首先需要声明你的类,然后访问它,否则像下面的代码会抛出一个ReferenceError:
let p = new Polygon();
// ReferenceError
class Polygon {}
//注意: 类表达式也存在与类声明相同的提升问题。
/* 匿名类 */
let Polygon = class {
constructor(height, width) {
this.height = height;
this.width = width;
}
};
/* 命名的类 */
let Polygon = class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
};
webpack2 demo
https://github.com/xiaomingming/webpack-demo