下面代码什么意思啊class A{ static instance(...args) { this.i = this.i || new this(...args) return this.i }}this.i = this.i || new this(...args)完全看不懂啊,这里this.i是个什么鬼new this(...args)又是什么?
1 回答
繁星coding
TA贡献1797条经验 获得超4个赞
短路。等同於:
class A{
static instance(...args) {
if (this.i) this.i = this.i;
else this.i = new this(...args);
return this.i;
}
}
new this(...args) is equal to new A(...args).
添加回答
举报
0/150
提交
取消