Javascript 数组解构并分配给类字段值?

Javascript 数组解构并分配给类字段值?,javascript,destructuring,Javascript,Destructuring,如何以简洁的方式编写此代码?我们可以分解数组并将其分配给类字段值吗?试试这个 函数傻瓜{ [this.x,this.y]=列表; } foo=新的foo[1,2]; console.logfoo.x; console.logfoo.y 试试这个 函数傻瓜{ [this.x,this.y]=列表; } foo=新的foo[1,2]; console.logfoo.x; console.logfoo.y;zx nx zy ny f no.split.forEachkey,idx=>{this[k

如何以简洁的方式编写此代码?我们可以分解数组并将其分配给类字段值吗?

试试这个

函数傻瓜{ [this.x,this.y]=列表; } foo=新的foo[1,2]; console.logfoo.x; console.logfoo.y 试试这个

函数傻瓜{ [this.x,this.y]=列表; } foo=新的foo[1,2]; console.logfoo.x; console.logfoo.y;zx nx zy ny f no.split.forEachkey,idx=>{this[key]=arr[idx];}zx nx zy ny f no.split.forEachkey,idx=>{this[key]=arr[idx];}
class ALU {
  constructor (x, y) {
    this.zx = '0' // Zero the x input
    this.nx = '0' // Negate the x input
    this.zy = '0' // Zero the y input
    this.ny = '0' // Negate the y input
    this.f = '0' // Function code: 1 for Add, 0 for And
    this.no = '0' // Negate the output
  }

  ...

  setControlBits (controlBits) {
    this.zx = controlBits[0]
    this.nx = controlBits[1]
    this.zy = controlBits[2]
    this.ny = controlBits[3]
    this.f = controlBits[4]
    this.no = controlBits[5]
  }

  ...
}