国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

將將類(lèi)的私有成員設(shè)置為構(gòu)造函數(shù)參數(shù)
P粉761718546
P粉761718546 2024-04-06 21:48:47
0
1
1823

class Foo {
  #one
  #two
  #three
  #four
  #five
  #six
  #seven
  #eight
  #nine
  #ten
  #eleven
  #twelve
  #thirteen
  #fourteen
  #fifteen
  #sixteen

  constructor(
    one,
    two,
    three,
    four,
    five,
    six,
    seven,
    eight,
    nine,
    ten,
    eleven,
    twelve,
    thirteen,
    fourteen,
    fifteen,
    sixteen
  ) {
    this.#one = one;
    this.#two = two;
    this.#three = three;
    this.#four = four;
    this.#five = five;
    this.#six = six;
    this.#seven = seven;
    this.#eight = eight;
    this.#nine = nine;
    this.#ten = ten;
    this.#eleven = eleven;
    this.#twelve = twelve;
    this.#thirteen = thirteen;
    this.#fourteen = fourteen;
    this.#fifteen = fifteen;
    this.#sixteen = sixteen;
  }
}

這個(gè)(反?)模式的解決方案是什么?

P粉761718546
P粉761718546

全部回復(fù)(1)
P粉010967136

對(duì)于任何想要使用構(gòu)造函數(shù)的人來(lái)說(shuō),擁有 16 個(gè)參數(shù)并不有趣。您在評(píng)論中提出的配置對(duì)象想法要有趣得多,當(dāng)然,當(dāng)您將其與擁有一個(gè)具有所有這些屬性的類(lèi)型對(duì)象的私有屬性的想法結(jié)合起來(lái)時(shí)。然后您可以使用 Object.assign 來(lái)根據(jù)用戶(hù)的首選項(xiàng)更新它:

class Foo {
  #options = {
    one: 1,
    two: 2,
    three: 3,
    four: 4
  }
  constructor(options = {}) {
    Object.assign(this.#options, options);
    console.log(this.#options);
  }
}

let foo = new Foo({three: 3000});
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板