Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jslint错误:意外的表达式';使用严格的';处于声明状态_Javascript_Angularjs_Jslint - Fatal编程技术网

Javascript jslint错误:意外的表达式';使用严格的';处于声明状态

Javascript jslint错误:意外的表达式';使用严格的';处于声明状态,javascript,angularjs,jslint,Javascript,Angularjs,Jslint,当我试图将以下代码保存在sublime文本中时 'use strict'; /*global angular,_*/ var app = angular.module("myApp", []); app.controller("myCtrl", function ($scope) { $scope.firstName = "John"; $scope.lastName = "Doe"; }); 我收到以下jslint错误: #1 Unexpected expressio

当我试图将以下代码保存在sublime文本中时

'use strict';
 /*global angular,_*/

 var app = angular.module("myApp", []);
 app.controller("myCtrl", function ($scope) {
   $scope.firstName = "John";
   $scope.lastName = "Doe";
 });
我收到以下jslint错误:

 #1 Unexpected expression 'use strict' in statement position.
    'use strict'; // Line 1, Pos 1
 #2 Place the '/*global*/' directive before the first statement.
    /*global angular,_*/ // Line 2, Pos 1
 #3 Undeclared 'angular'.
    var app = angular.module("myApp", []); // Line 4, Pos 11
 #4 Expected 'use strict' before '$scope'.
    $scope.firstName = "John"; // Line 6, Pos 3
 #5 Expected '$scope' at column 5, not column 3.
    $scope.lastName = "Doe"; // Line 7, Pos 3

您不能使用
“使用严格”使用jslint以全局方式存在。看

考虑到这一点,您需要将其从全局范围中删除,并将其添加到函数范围中,或者将所有内容包装到IFEE中

 /*global angular,_*/
 var app = angular.module("myApp", []);
 app.controller("myCtrl", function ($scope) {
  'use strict';
   $scope.firstName = "John";
   $scope.lastName = "Doe";
 });
或将其包装:

/*global angular,_*/
(function(){
  'use strict';
   var app = angular.module("myApp", []);
   app.controller("myCtrl", function ($scope) {
     $scope.firstName = "John";
     $scope.lastName = "Doe";
   });
})();

我已经检查了那个链接@TheSharpieOne。这不符合我的目的所以。。答案中说“根据,JSLint的浏览器选项会自动禁用”use strict“的使用;在全局级别上。据我所知,没有办法重新启用它。”这一部分没有帮助您认识到您不能将
“use strict”放在在那里,这就是问题所在?如果没有使用“use strict”,那么jslint错误会持续出现,说“在“$scope”之前应该使用“use strict”。是,但不是。jslint使用错误消息处理换行:“不要在paren中换行函数文本。”