Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yet another 'Uncaught TypeError: Cannot call method 'apply' of undefined '

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:

enter image description here

It works if on its own with no other JS but when combined on the same page as other scripts I get the error.

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 ); }:

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 );
        }
    };
like image 653
egr103 Avatar asked Mar 14 '13 16:03

egr103


2 Answers

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

Instead of:

event.type = "myType";
jQuery.event.handle.apply(this, arguments);

Use:

jQuery.event.simulate('myType', this, event);
like image 57
Karl Forshaw Avatar answered Oct 05 '22 11:10

Karl Forshaw


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.

To my knowledge, this was never a supported property.

http://jsfiddle.net/xPJN4/

like image 21
the system Avatar answered Oct 05 '22 11:10

the system