anvd anvd - 1 year ago 169
Javascript Question

jQuery.event.handle is undocumented and deprecated

I am using a plugin that has this block of code. However i am getting this error

JQMIGRATE: jQuery.event.handle is undocumented and deprecated

*Cause: jQuery.event.handle was never documented, and deprecated with jQuery 1.7 (see As of jQuery 1.9, it has been removed.

Solution: Use documented jQuery APIs, such as

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 ); //here
}, execAsap === "execAsap"? 0 : 50 );

So, this line will be changed to what?

jQuery.event.handle.apply( context, args );

Answer Source

I'm guessing context must be the element and args the arguments passed into that custom event, so maybe something like this should work:

$(this).trigger(event, [args]);

I would suggest refactoring the whole thing to use on instead of bind. Then you can trigger custom events defined with on very easily, I don't think using this approach you need to define a custom event so you could make the code a bit smaller.