jQuery を広く使用している Web サイトがあり、Firefox と IE で正常に動作します。ただし、Chrome では、頻繁に (そして半ランダムに) 取得していますUncaught TypeError: Cannot call method 'apply' of undefined
(また、他の jQuery メソッドが の代わりに表示されますapply
)。
問題を追跡して jQuery メソッドにたどり着きpushStack()
ました。
元のソース コード (jQuery 1.7.1):
// Take an array of elements and push it onto the stack
// (returning the new matched element set)
pushStack: function( elems, name, selector ) {
// Build a new jQuery matched element set
var ret = this.constructor();
// (etc.)
}
インストルメント化されたコード:
pushStack: function( elems, name, selector ) {
if (!(this instanceof jQuery.fn.init)) throw this;
// Build a new jQuery matched element set
var ret = this.constructor();
if (!(ret instanceof jQuery.fn.init)) {
console.log("pushStack>this: " + this.constructor);
console.log("pushStack>ret: " + ret.constructor);
throw ret;
}
// (etc.)
}
ほとんどの場合pushStack()
、正しく実行されます。Object
ただし、Chrome は の代わりにtype のオブジェクトを作成することがありjQuery.fn.init
ます。コンソール出力:
pushStack>this: function ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
}
pushStack>ret: function Object() { [native code] }
Uncaught #<Object>
誰かが同様の問題に遭遇しましたか? それはChromeの(既知の)バグですか?
アップデート
独自にロードできるように、ページを単純化することができました。Chromium プロジェクト project のバグを埋めました。問題を再現するためのページがそこに添付されています。