本文介绍了jslint错误:意外'在'。与undefined比较,或使用hasOwnProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下javascript函数未通过jslint检查

 函数hasActiveX(){
return(' ActiveXObject'在窗口中);
}

jslint错误

 意外'输入'。与undefined比较,或使用hasOwnProperty方法。 

我应该忍受jslint错误,还是有更好的方法来确定ActiveXObject?
我找不到跳过此检查的jslint标志?

解决方案

我认为JSLint要求您尝试:

  function hasActiveX(){
return window.hasOwnProperty('ActiveXObject');
}

或者与undefined进行比较的其他建议:

  return(typeof(window.ActiveXObject)!=undefined); 


阅读完评论之后,如果JSLint停止抱怨,似乎中的实际上是有用的,否则我会尝试上面的选项2。 / p>

I have the following javascript function that fails a jslint check

  function hasActiveX() {
    return ('ActiveXObject' in window);
  }

jslint error

Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead.

should I just live with the jslint error, or is there a better way to determine ActiveXObject?I could not find a jslint flag to skip this check?

解决方案

I think JSLint is asking you to try:

function hasActiveX() {
    return window.hasOwnProperty('ActiveXObject');
}

Or the other suggestion of comparing against "undefined":

return (typeof(window.ActiveXObject) != "undefined");

After reading the comments, it seems like in is actually useful if JSLint would stop complaining about it, otherwise I would try option 2 above.

这篇关于jslint错误:意外'在'。与undefined比较,或使用hasOwnProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 01:01