【发布时间】:2019-03-10 03:01:09
【问题描述】:
我有一个函数,我正在测试 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
【问题讨论】:
-
您到底想优化什么?看起来一点也不差。
-
return ($scope.postParams.options.scopes.report.from || $scope.postParams.options.scopes.report.to || $scope.postParams.options.template_id || $scope.displayOptions.query.length > 0) -
嗨@Timggwp,感谢您的评论,这个结构看起来不错?还有其他语法看起来比这更好吗?
-
你在寻找破坏吗??
-
如果我错了,请纠正我,但这不是 JS
$scope.filterActivated = ->的有效语法。如果这是一个箭头函数,则必须有= () =>用于无参数
标签: javascript function if-statement coffeescript