开发者

Access jQuery user defined function within said function via sub function

I was wondering how I could access the jQuery custom function within a sub function which is defined through an object. Observe:

(function($){
    var methods = {
        init    : function ( options ) {
            // getting the variable "data".
            $.each (data, function(itemid, toll){
                $.notification("update", data);
            });
        },
        update  : function ( options ) {
            // ...
        }
    };
    $.fn.notification = function ( method ) {
        if ( methods[method] ) {
            return methods[method].ap开发者_开发百科ply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        }
    };
})(jQuery);

The above method, using $.notification ("update", data); does not work, because the function is in the middle of being defined. So, how does one access the above function, without repeating code? i.e. writing a function just to update, outside of the method variable, and then placing that function within the update index of the method variable? Thank you in advanced. :3


Use the below line to execute it

$().notification("update", data);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜