这个问题在这里已经有了答案:
JSLint is suddenly reporting: Use the function form of "use strict"
(9 个回答)
7年前关闭。
这是我的文件:app/scripts/controllers/main.js
"use strict";
angular.module('appApp')
.controller('MainCtrl', ['$scope', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}]);
我的
Gruntfile.coffee
已:jshint:
options:
globals:
require: false
module: false
console: false
__dirname: false
process: false
exports: false
server:
options:
node: true
src: ["server/**/*.js"]
app:
options:
globals:
angular: true
strict: true
src: ["app/scripts/**/*.js"]
当我跑
grunt
,我得到:Linting app/scripts/controllers/main.js ...ERROR
[L1:C1] W097: Use the function form of "use strict".
"use strict";
最佳答案
问题是,如果您不使用函数形式,它适用于所有内容,而不仅仅是您的代码。解决方案是范围 use strict
您控制的内部功能。
引用这个问题:JSLint is suddenly reporting: Use the function form of “use strict” .
而不是做
"use strict";
angular.module('appApp')
.controller('MainCtrl', ['$scope', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}]);
你应该做
angular.module('appApp')
.controller('MainCtrl', ['$scope', function ($scope) {
"use strict";
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}]);
要么就是这样,要么将您的代码包装在一个自动执行的闭包中,如下所示。
(function(){
"use strict";
// your stuff
})();
关于jshint "use strict"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19910134/