javascript 另一个“未捕获的类型错误:无法调用未定义的方法‘应用’”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15415172/
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
Yet another 'Uncaught TypeError: Cannot call method 'apply' of undefined '
提问by egr103
My chances are slim with this but I've tried a couple of solutions via Google but nothing seems to fix the 'Uncaught TypeError: Cannot call method 'apply' of undefined ', anonymous function:
我的机会很小,但我已经通过 Google 尝试了几种解决方案,但似乎没有任何解决方案可以解决“未捕获的类型错误:无法调用未定义的方法“应用”,匿名函数:
It works if on its own with no other JS but when combined on the same page as other scripts I get the error.
它在没有其他 JS 的情况下单独工作,但是当与其他脚本在同一页面上组合时,我收到错误消息。
The lines of code it refers to are the following with line 32 being the culprit. Line 32 is this line - if ( resizeTimeout ) { clearTimeout( resizeTimeout ); }
:
它引用的代码行如下,第 32 行是罪魁祸首。第 32 行是这一行 - if ( resizeTimeout ) { clearTimeout( resizeTimeout ); }
:
var $event = $.event, resizeTimeout;
$event.special.smartresize = {
setup: function() {
$(this).bind( "resize", $event.special.smartresize.handler );
},
teardown: function() {
$(this).unbind( "resize", $event.special.smartresize.handler );
},
handler: function( event, execAsap ) {
// Save the context
var context = this,
args = arguments;
// set correct event type
event.type = "smartresize";
if ( resizeTimeout ) { clearTimeout( resizeTimeout ); }
resizeTimeout = setTimeout(function() {
jQuery.event.handle.apply( context, args );
}, execAsap === "execAsap"? 0 : 100 );
}
};
采纳答案by the system
Guessing you're loading a newer version of jQuery. It appears as though jQuery 1.9
and later does not have the jQuery.event.handle
property.
猜测您正在加载较新版本的 jQuery。看起来好像jQuery 1.9
和后来没有jQuery.event.handle
财产。
To my knowledge, this was never a supported property.
据我所知,这从来都不是受支持的财产。
回答by Karl Forshaw
I managed to figure this out by looking at the code, there is a method called "simulate" which you can use to "Piggyback on a donor event to simulate a different one.", "Fake originalEvent to avoid donor's stopPropagation, but if the simulated event prevents default then we do the same on the donor." This struck me as the purpose of "setting the event type in Brandon Aaron's tutorial
我通过查看代码设法弄清楚了这一点,有一种称为“模拟”的方法,您可以使用它来“搭载捐助者事件以模拟不同的事件。”,“伪造原始事件以避免捐助者的停止传播,但是如果模拟事件防止违约,然后我们对捐助者做同样的事情。” 这让我印象深刻,因为“在 Brandon Aaron 的教程中设置事件类型
Instead of:
代替:
event.type = "myType";
jQuery.event.handle.apply(this, arguments);
Use:
利用:
jQuery.event.simulate('myType', this, event);
回答by ajon
I encountered this error when I accidentally loaded the newest version of jquery
in the head, then loaded an older version of jquery
after it. The older version didn't have the methods that I needed from the newer version.
当我不小心加载了最新版本jquery
的头部,然后加载了jquery
它之后的旧版本时,我遇到了这个错误。旧版本没有我从新版本中需要的方法。
回答by TheGerbil
I had this error using older versions of jQuery and masonry.min.js - I no longer have the un-minified code!
我在使用旧版本的 jQuery 和 masonry.min.js 时遇到了这个错误 - 我不再有未缩小的代码!
Replacing:
更换:
b.event.handle.apply(d,f)
With
和
b.event.simulate('smartresize', d, f)
Sorted the problem and the scripts are working fine now, credit to @karl-forshaw for the fix... I would comment in replay but lack the reputation to do so!
对问题进行排序,脚本现在工作正常,感谢@karl-forshaw 的修复......我会在重播中发表评论,但缺乏这样做的声誉!
回答by Rijo Abraham
My error was fixed when I linked to jQuery Migrate.
当我链接到 jQuery Migrate 时,我的错误得到了修复。
JQMIGRATE: Migrate is installed, version 1.4.1
JQMIGRATE:已安装Migrate,版本1.4.1
No more errors. For me the isotope.js was causing this issue. Hope it helps random person. :)
没有更多的错误。对我来说,isotope.js 导致了这个问题。希望它可以帮助随机的人。:)