我正在反对这一点.每5-10次我重新加载我的应用程序,我得到一个源自jQuery的奇怪错误.我尝试在非压缩版本的jQuery中添加断点以尝试从错误中退出,但Chrome永远不会为它们停止,而是始终跳过错误.
我正在使用jQuery 1.7.2,但在1.7和1.6.1版本中也会出现此错误.
在我的javascript应用程序中,我将这行代码称为:
this.element.find('.banner-btn')
Run Code Online (Sandbox Code Playgroud)
this.elementjQuery对象在哪里?这没有理由导致问题,10次中有9次没有问题.但随机的东西会中断,然后每次调用该行代码时,结果都是此堆栈跟踪的一些变体:
Uncaught TypeError: Cannot call method 'apply' of undefined
makeArrayjquery-1.7.2.js:4858
Sizzlejquery-1.7.2.js:5110
jQuery.fn.extend.findjquery-1.7.2.js:5432
Run Code Online (Sandbox Code Playgroud)
事实上,在这个打破之后的任何时候我都会调用$ .fn.find我得到这个错误.我已经尝试了各种各样的东西,我一直在阅读jQuery源代码,而且我无法在这方面做到.任何人都知道该把它钉在哪里?
我已经将这个进一步追踪到jQuery库中,并找到了错误首次出现的位置.的种类.
为了跟踪DOM遍历,jQuery使用pushStack方法.这是在jQuery.fn.find方法中调用的,应该返回一个jQuery对象.它通常会这样做 - 但是当jQuery内部出现错误时,此函数只返回一个常规对象,没有jQuery好东西.这会导致错误.
好的,这是pushStack的第一个小部分源代码,在jquery-1.7.2.js的第241行定义:
// Take an array of elements and push it onto the stack
// (returning the new matched element set)
pushStack: function( elems, name, selector ) {
if(window._debug_jQuery_pushStack) { debugger }
// Build a new jQuery matched element set
var ret = this.constructor();
// ---- the function continues, but this is enough for us ----
Run Code Online (Sandbox Code Playgroud)
其中位var ret = this.constructor();要加的,其中jQuery的东西应该.在这种情况下,他们不是.不知何故this已被破坏成常规对象,而不是jQuery.所以现在我的问题是:我如何找到这种腐败的原因?困难在于,这仅在我的应用程序加载10或20次中出现,并且看起来完全是随机的.
问题不在您的代码中,而是在Chrome本身 - 请参阅错误#125148.目前的解决方法是更改pushStack,如下所示:
pushStack: function( elems, name, selector ) {
// Build a new jQuery matched element set
var ret = this.constructor();
// temporary workaround for chrome issue #125148
// http://code.google.com/p/chromium/issues/detail?id=125148
if (!(ret instanceof jQuery.fn.init)) {
console.log("applying pushStack fix");
ret = new jQuery.fn.init();
}
// ... snip ...
Run Code Online (Sandbox Code Playgroud)
另外,请参阅此相关问题.
| 归档时间: |
|
| 查看次数: |
1506 次 |
| 最近记录: |