This function has too many statements. (41)

旧时模样 提交于 2019-12-05 07:48:19
Reacting

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;

you can do this:

$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();

that will fix it.

UPDATE

Let me explain:

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 :)

The best way to get rid of the error would be to edit your jshint settings to not display it.

http://jshint.com/docs/options/#maxstatements

That's a very wishy-washy jshint warning that doesn't really mean anything.

Normally, a function that requires more than 4 or 5 parameters is a bad idea for a lot of reasons, but isn't technically wrong. In this case those params are Angular's way of defining dependencies, so shouldn't be a problem. If the code works, I wouldn't worry about it.

If the controller wants more statements and you don't have any other method to remove it then go to your .jshintrc file and edit it like

"maxstatements": 80, // or whatever number you want'

thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!