有人可以给我建议吗?我刚开始使用 jslint,我收到一条错误消息“strict violation”指向带有“dialog(this)”的行 -
function accessLinkClick(e) {
e.preventDefault();
$('.accessLink')
.unbind('click', accessLinkClick);
dialog(this);
}
function accessControls() {
$('.accessLink')
.bind('click', accessLinkClick);
$('#logoutLink')
.click(function (e) {
window.location = $(this).attr('data-href');
});
}
我以前从未见过这条消息。这是什么意思?
最佳答案
规范的附件 C 是这样解释的:
If
this
is evaluated within strict mode code, then the this value is not coerced to an object. Athis
value ofnull
orundefined
is not converted to the global object and primitive values are not converted to wrapper objects. Thethis
value passed via a function call (including calls made using Function.prototype.apply and Function.prototype.call) do not coerce the passedthis
value to an object (10.4.3, 11.1.1, 15.3.4.3, 15.3.4.4).
在上述代码中使用e.target
代替this
。
引用资料
关于javascript - 在 javascript 中使用 this 关键字时出现严重违规是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12603340/