javascript IE8 上“类型错误对象不支持此属性或方法”的一般解决方案是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9631100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:17:06  来源:igfitidea点击:

What's the general solution to "typeerror object doesn't support this property or method" on IE8?

javascriptinternet-explorer

提问by ripper234

I saw several specific questions about this problem - getting typeerror object doesn't support this property or methodin IE8, each with its specific answer.

我看到了几个关于这个问题的具体问题 - 进入typeerror object doesn't support this property or methodIE8,每个问题都有其特定的答案。

Suppose I have a large website with lots of code ... I don't know what specific snippet is causing this error.

假设我有一个包含大量代码的大型网站......我不知道是什么特定片段导致了这个错误。

Is there a general method to debug this? I've tried with the IE Developer Tools, and it doesn't break on error. Is this caused by incorrect javascript syntax? Should I try something like js lint?

有没有通用的方法来调试这个?我已经尝试过使用 IE 开发人员工具,它不会因错误而中断。这是由不正确的 javascript 语法引起的吗?我应该尝试像 js lint 这样的东西吗?

What's the correct, general way to identify and deal with this problem?

识别和处理此问题的正确、通用的方法是什么?

回答by ripper234

OK, so I turned to the age old solution and started to delete massive chunks of code from my project until the problem was "fixed". This helped me locate the problematic file.

好的,所以我转向了古老的解决方案并开始从我的项目中删除大量代码,直到问题被“修复”。这帮助我找到了有问题的文件。

I then proceeded to delete function by function until I found this little snippet: str.trim(). A quick search turned this up.

然后我继续逐个删除函数,直到找到这个小片段:str.trim(). 一个快速搜索把这个了

Update: Actually, I just realized something ... the problem was just a normal exception, and passing it to alert()masked the details. If you let such exceptions go to the top, then whatever browser you use will display useful line information. So, the next time it happens to me, I'm going to look for a way to make the exceptions fly high outside of the top level function. The catchwasn't in my code, it was jQuery, so I'm still not quite sure how to do it.

更新:实际上,我刚刚意识到一些事情......问题只是一个正常的异常,并通过它来alert()掩盖细节。如果您让此类异常出现在顶部,那么您使用的任何浏览器都会显示有用的行信息。所以,下次它发生在我身上时,我将寻找一种方法让异常在顶级函数之外飞得更高。将catch在我的代码是不是,这是jQuery的,所以我还是不太清楚如何去做。