【发布时间】:2018-05-23 13:18:10
【问题描述】:
有这2个代码sn-ps。它们之间有什么区别?在什么情况下你更喜欢一个?
export default class A {
static methodA() {
console.log('Method A');
}
}
有以下用法:
import A from 'a';
function test() {
A.methodA()
}
VS这第二个sn-p:
class A {
methodA() {
console.log('Method A');
}
}
export default new A();
有以下用法:
import A from 'a';//I know that semantically I should have import a - but for the sake of this question I wrote import A.
function test() {
A.methodA();
}
【问题讨论】:
标签: javascript class ecmascript-6 static instance