Javascript 类在 Chrome 上运行良好,但在 Edge 上运行不佳。为什么?

标签 javascript html

我定义了一个类(如以下代码所示),该类在 Chrome 中运行良好,但在 Edge 中运行不佳。使用Edge的调试器出现以下错误:

SCRIPT1005: Expected ( in Line 4 and Column 11.

你知道出了什么问题吗?提前致谢。

注意 SimulationPMSM 是在代码的以下部分中定义的另外两个对象。

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_PlayFlag_PauseFlag_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/

相关文章:

php - 在 JavaScript 中处理 AJAX 调用的 PHP 返回的数据

javascript - 自调用匿名函数语法

javascript - 如何在 2 个单独的 Div 中自动调整文本大小

html - 如何将一个 div 放在另一个下面?

html - Magento eshop 1.7.0.2 的响应式设计方法

javascript - PhantomJS 无法在 JavaScript 页面上运行,错误 "Activate JavaScript"

javascript - Ajax Post与express js获取req参数错误

javascript - 这种使用回调和参数的方式正确吗?

jquery - 在 Silverstripe 3 中加载带有滑动动画的新页面(使用 Ajax?)

javascript - 如何在模态 Bootstrap 中发送参数?