例如,我试图在课堂上从中进行全局解构
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;
}
}
而不是在每个方法中解构 this 有没有办法将它作为所有方法的全局
在每个方法中,我只是引用变量而不是调用它
蝴蝶刀刀
相关分类