我有一个函数,正在测试 4 个变量,我想优化 if 语句测试的结构,有人可以帮忙吗? :
$scope.filterActivated = ->
if $scope.postParams.options.scopes.report.from || $scope.postParams.options.scopes.report.to || $scope.postParams.options.template_id || $scope.displayOptions.query.length > 0
return true
else
return false
最佳答案
您可以删除true/false
并像这样优化它:
$scope.filterActivated = ->
options = $scope.postParams.options
options.scopes.report.from or options.scopes.report.to or options.template_id or $scope.displayOptions.query.length > 0
编辑:JS给你:
$scope.filterActivated = () => {
let options = $scope.postParams.options;
return options.scopes.report.from || options.scopes.report.to || options.template_id || $scope.displayOptions.query.length > 0;
};
关于使用 CoffeeScript 语法的 JavaScript - if 条件 : optimize if statement structure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52651463/