How to structure my javascript/jquery code?

前端 未结 10 897
我寻月下人不归
我寻月下人不归 2020-12-12 09:22

I am toying around with a pretty intensive ajax based jquery web application. It is getting to a point where I almost loose track of what events that should trigger what act

10条回答
  •  有刺的猬
    2020-12-12 10:08

    (function($, window, slice)
    {
    
        $.subscribe = function(eventName, obj, method)
        {
            $(window).bind(eventName, function()
            {
                obj[method].apply(obj, slice.call(arguments, 1));
            });
            return $;
        };
    
        $.publish = function(eventName)
        {
            $(window).trigger(eventName, slice.call(arguments, 1));
            return jQuery;
        };
    
    })(jQuery, window, Array.prototype.slice);
    

提交回复
热议问题