1
我已经得到了以下(简化)Batman.js
文件:解决可能违反严格(和帮助蝙蝠侠拯救哥谭)
(function(){
"use strict";
window.Batman = function(){
// Global references
this.version = "1.0.1";
};
Batman.prototype.saveGotham = function(params) {
var _ = this; // Works fine
destroyGotham.call(_, params);
};
// Private
function destroyGotham(params){
var _ = this; // <!-- "possible strict violation"
}
}());
JSHint抱怨一个possible strict violation
在指示线。我如何避免这种情况而不删除"use strict"
?
P.S:我想麻烦var _ = this
引用Batman
实例。
我该如何解决? – FloatingRock
您在忽略jshint时会调用函数以便定义'this', – adeneo
谢谢 - 我发现您可以在抱怨上方的行上添加'/ * jshint validthis:true * /' 'var _ = this;'来压制错误。 – FloatingRock