将每个实例添加到构造函数中的数组:
class Abc {
constructor(arg) {
this.arg = arg;
Abc.instances.push(this);
}
}
Abc.instances = [];
new Abc('qwe');
new Abc('rty');
console.log(Abc.instances);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60 次 |
| 最近记录: |