我定义了一个类(如以下代码所示),该类在 Chrome 中运行良好,但在 Edge 中运行不佳。使用Edge的调试器出现以下错误:
SCRIPT1005
: Expected(
in Line 4 and Column 11.
你知道出了什么问题吗?提前致谢。
注意 Simulation
和 PMSM
是在代码的以下部分中定义的另外两个对象。
class Event_Class {
Flag_Play;
Flag_Pause;
Flag_Stop;
Initialize() {
this.Flag_Play = false;
this.Flag_Pause = false;
this.Flag_Stop = false;
}
Play() {
this.Flag_Play = true;
this.Flag_Pause = false;
this.Flag_Stop = false;
}
Pause() {
this.Flag_Play = false;
this.Flag_Pause = true;
this.Flag_Stop = false;
}
Stop(Simulation, PMSM) {
this.Flag_Play = false;
this.Flag_Pause = false;
this.Flag_Stop = true;
Simulation.Initialize();
PMSM.Initialize();
}
}
最佳答案
这是因为Flag_Play
、Flag_Pause
和Flag_Stop
都定义为public fields.当前版本的 Edge 不支持公共(public)字段,但当 Edge 更新到基于 Chromium 的新版本(与 Chrome 相同的平台)时,将支持公共(public)字段。
要获得两种浏览器的完全支持,请使用构造函数
方法来定义您的属性并为其分配值。
每当您创建新实例时,构造函数都会被执行。
请参阅下面的示例。
class Event_Class {
constructor() {
this.Flag_Play = false;
this.Flag_Pause = false;
this.Flag_Stop = false;
}
initialize() {
关于Javascript 类在 Chrome 上运行良好,但在 Edge 上运行不佳。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59443988/