node cross-env 无法设置 class 变量

node cross-env can't set the class variables

我正在使用 node v12.22.9npm 8.5.1 并安装了 cross-env: "^7.0"

ERROR in ./resources/js/frontend/eyesonMeeting.js
Module build failed: SyntaxError: Unexpected token (4:10)

  2 | 
  3 |  class eyesonMeeting {
> 4 |     audio = true
    |           ^

如何设置 class 变量而不发生冲突? 我试图用 laravel-mix 替换 cross-env 但我遇到了与 sass 的冲突。

package.json 脚本:

"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",

当您使用 classes 时,您可以使用构造函数通过 this

设置 class 变量
class eyesonMeeting {
  constructor() {
    this.audio = true;
  }

  // example using audio in a different function
  someFunctionSettingAudioFalse() {
    this.audio = false;
  }

  hasAudio() {
    return this.audio;
  }
}