亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

數組解構并分配給類字段值?

數組解構并分配給類字段值?

胡說叔叔 2023-08-24 17:52:23
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]  }  ...}如何簡潔地編寫這段代碼?就像我們可以解構數組并將其分配給類字段值嗎?
查看完整描述

1 回答

?
九州編程

TA貢獻1785條經驗 獲得超4個贊

試試這個。


function Foo(list) {

    [this.x, this.y] = list;

}


foo = new Foo([1, 2]);


console.log(foo.x);

console.log(foo.y);


查看完整回答
反對 回復 2023-08-24
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號