【问题标题】:Method for safe getting property in angularjs/lodash在 angularjs/lodash 中安全获取属性的方法
【发布时间】:2016-09-28 10:20:54
【问题描述】:

我有以下代码:

return _.map(_.compact([
                $scope.status() ? false : "status",
                ($scope.evidenceLevel || {}).id ? false : "evidence_level",
                ($scope.association || {}).id ? false : "association",
                $scope.predictiveStatement ? false : "predictive_statement",
                $scope.evidenceStatement ? false : "evidence_statement",
                ($scope.hasIncludedReference() || isReferred()) ? false : "reference"
            ]), myFunction);

Sonarqube 认为这个方法太复杂了(复杂度为 11,允许的最大值为 10),这样的代码有没有标准函数 - ($scope.association || {}).id?

【问题讨论】:

    标签: javascript angularjs sonarqube lodash ecma


    【解决方案1】:

    您最终可以使用_.defaults。由下划线支持,可能由 lodash 支持。

    http://underscorejs.org/#defaults

    【讨论】:

      猜你喜欢
      • 2016-02-06
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      相关资源
      最近更新 更多