Skip to content Skip to sidebar Skip to footer

Chain .ready And .resize Into Function?

Inside this object, I have a property Response.action that is meant to be a shorthand for triggering code on jQuery's .ready and .resize simultaneously. The comment in the code blo

Solution 1:

How about

window.Response = (function ( $, window, undefined ) {

    var Response = {};

    Response.action = function ( func ) {
        if ( typeof func !== 'function' ) { return false; }

        $(function () {
            func();
            $( window ).resize( func );
        });

        return func;
    };

    return Response;

})( jQuery , window );

Post a Comment for "Chain .ready And .resize Into Function?"