【发布时间】:2020-04-24 16:41:28
【问题描述】:
假设我有一个类,其方法如下:
class MyClass {
importantMethod() {
... //any code here
}
}
假设我有 10/20/更多类的实例,例如:
const inst1 = new MyClass();
const inst2 = new MyClass();
const inst3 = new MyClass();
.... //and more instances here
有没有办法以比以下更优雅的方式在每个实例上执行importantMethod():
inst1.importantMethod()
inst2.importantMethod()
inst3.importantMethod()
.... //and for all the instances
【问题讨论】:
标签: javascript class oop