如何在课堂上进行全球销毁?

时间:2020-10-09 09:52:07

标签: javascript

例如,我试图在课堂上对此进行全局破坏

class Car {
    constructor(
        color,
        speed,
        type,
    ) {
        this.color = color;
        this.speed = speed;
        this.type = type;
    }

    method1() {
      const { color, speed, type } = this;
      // do something with speed, color, type;
    }

    method2() {
        const { color, speed, type } = this;
        // do another thing with speed, color, type;
    }

    method3() {
        const { color, speed, type } = this;
        // do another thing with speed, color, type;
    }
}

不是在每种方法中都对其进行破坏,而是有一种方法可以将其作为所有方法的全局方法

在每个方法中,我都只引用变量

,而不是调用它

1 个答案:

答案 0 :(得分:2)

不,没有。如果要在每种方法中创建局部变量,则不能全局进行。

唯一的选择是不使用<InputDialogContent onChange={e => setEnableLoginButton(isValidEmail(e.target.value))} ... /> ,而是使用工厂函数来构造构造函数参数的闭包:

class
相关问题