【发布时间】:2021-10-25 23:49:26
【问题描述】:
下面的第一个代码示例是我今天正在做的,我在构造函数中初始化全局变量。
但是,如第二个示例所示,将全局变量移出类会不会有任何危害?
class Alert {
constructor(alert) {
this.load = JSON.parse('{}');
this.alert = alert;
this.#coolDownTime = 0;
};
#coolDownTime;
}
vs 只是做
class Alert {
constructor(alert) {
this.alert = alert;
};
#coolDownTime = 0;
#load = JSON.parse('{}');
}
【问题讨论】:
标签: javascript node.js oop ecmascript-6 ecmascript-2016