该函数有太多语句. (41) [英] This function has too many statements. (41)
问题描述
我有这个控制器
.controller('ctrl', function($scope, $rootScope, $timeout, $alert,
$location, $tooltip, $popover, BetSlipFactory,
AccordionsFactory, AuthFactory,
RiskWinCalculations) {...});
,由于jshint
,我收到此错误:
and, I am getting this error due to jshint
:
第10行第44列该函数有太多语句. (41)
line 10 col 44 This function has too many statements. (41)
那么,我应该怎么避免呢?
so, what should I do to avoid it ?
推荐答案
这并不意味着@pankajparkar之前说过的代码管理不善,可能是因为您有类似的东西,让我在我的一个项目中这样说:
It doesn't mean poorly managed code as @pankajparkar says before, it could be because you have something like this, lets say this from one of my projects:
$scope.betLoader = false;
$scope.showIfbetAlerts = true;
$scope.displayStraight = true;
$scope.displayParlay = true;
$scope.displayIfBet = true;
$scope.displayTeaser = true;
$scope.displayPleaser = true;
$scope.displayReverse = true;
$scope.unavailableBet = false;
$scope.subAccordion = false;
$scope.betTypeShow = false;
$scope.showStraight = true;
您可以执行以下操作:
$scope.setInitialState = function() {
$scope.betLoader = false;
$scope.showIfbetAlerts = true;
$scope.displayStraight = true;
$scope.displayParlay = true;
$scope.displayIfBet = true;
$scope.displayTeaser = true;
$scope.displayPleaser = true;
$scope.displayReverse = true;
$scope.unavailableBet = false;
$scope.subAccordion = false;
$scope.betTypeShow = false;
};
$scope.setInitialState();
这将解决它.
更新
让我解释一下:
它不仅与依赖关系有关,当语句过多时,jslint会引发此错误,他在第10行(控制器开始的地方)之前说过,因此从那里分开,他应该有太多的语句,如果您将所有这些语句放入1个函数中,这些语句将减少为1 :)
it is not only related with the dependencies, jslint throws this error when there are too many statements, he says before on line ten which is where the controller begins, so parting from there, he should have too many statements, if you put all those statements in 1 function, those statements will be reduce to 1 :)
这篇关于该函数有太多语句. (41)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!