0

この種の多重ネストされた if-else ブロックがあります。私の理解では、その必要性を排除してコードを削減するのに役立つ「データ駆動型」のアプローチがあるということですが、私はまだ大規模な方法で経験していないので、このコードのリファクタリングを手伝ってくれる人はいますか? 「データドリブン」アプローチで作業するには?

function (arg1) {
  if(this.thing[arg1]){
    // there is a valid property for this arg1
    if(this.thing.a){
      // there exists an 'a' propertie also
      if(this.thing.a.arg1 == arg1){
        // the a property has a property is the same as the arg1    
        // if this 'a' has a number higher than 0, avoid doing anything
        if(this.thing.a.number > 0){
        }else{
          // 'a' number was 0 or lower, so we do something
          this.thing.a = this.thing[arg1];
          this.thing.a.arg1 = arg1;
        }
      }else{
        // the' a' is not the arg1
        // so we want to use the current arg1!
        // but only if its 'number' is lower than 1
        if(this.thing.a.number > 0){
        }else{
          // 'a' number was 0 or lower, so we do something
          this.thing.a = this.thing[arg1];
          this.thing.a.arg1 = arg1;
        }
      }
    }else{
      // there is no thing.a so we set it to arg1 
      this.thing.a = this.thing[arg1];
      this.thing.a.arg1 = arg1;
    }
  }
}
4

1 に答える 1