javascript-jslint错误:语句位置出现意外的表达式’use strict’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-jslint错误:语句位置出现意外的表达式’use strict’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1358字,纯文字阅读大概需要2分钟。
内容图文
这个问题已经在这里有了答案: > How to set ‘use strict’ globally with JSLint 2个
当我尝试将以下代码保存为精美文字时,
'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在全球范围内.查看https://stackoverflow.com/a/35297691/1873485
考虑到这一点,您需要将其从全局范围中删除,并将其添加到函数范围中,或将所有内容包装在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";
});
})();
内容总结
以上是互联网集市为您收集整理的javascript-jslint错误:语句位置出现意外的表达式’use strict’全部内容,希望文章能够帮你解决javascript-jslint错误:语句位置出现意外的表达式’use strict’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。