如何防止 "missing use strict" 在 IIFE 末尾分配给变量?
How to prevent "missing use strict" at end of IIFE assigned to variable?
使用 jshint,如果你有类似的东西:
var Thing = (function(){
"use strict";
// code and stuff...
}());
我在最后一行收到 "missing use strict" 错误。我想这是因为 var Thing =
超出了严格的范围。有没有办法在不完全关闭使用严格警告的情况下阻止此警告?
您可以再使用一个包装器:
(function(namespace) {
'use strict';
namespace.Thing = (function() {
// code here
})();
})(window);
在您的 .jshintrc 中,删除 globalstrict: true
并使用 strict: true
http://jshint.com/docs/options/#strict
globalstrict
用于文件范围 'use strict' 并且 strict
用于功能范围(您想要的)。
使用 jshint,如果你有类似的东西:
var Thing = (function(){
"use strict";
// code and stuff...
}());
我在最后一行收到 "missing use strict" 错误。我想这是因为 var Thing =
超出了严格的范围。有没有办法在不完全关闭使用严格警告的情况下阻止此警告?
您可以再使用一个包装器:
(function(namespace) {
'use strict';
namespace.Thing = (function() {
// code here
})();
})(window);
在您的 .jshintrc 中,删除 globalstrict: true
并使用 strict: true
http://jshint.com/docs/options/#strict
globalstrict
用于文件范围 'use strict' 并且 strict
用于功能范围(您想要的)。