代码之家  ›  专栏  ›  技术社区  ›  Lonely

重构JavaScript/TypeScript:避免重复属性

  •  0
  • Lonely  · 技术社区  · 7 年前

    我如何缩短以下语句

      ratingsExisting(): boolean {
        return (
          this.fromAPIData.book &&
          this.fromAPIData.book.misc &&
          this.fromAPIData.book.misc.ratings &&
          this.fromAPIData.book.misc.ratings.length > 0
        );
      }
    

    所以如果有任何属性是 null

    0 回复  |  直到 7 年前
    推荐文章