【问题标题】:Access jQuery user defined function within said function via sub function通过子函数访问所述函数中的jQuery用户定义函数
【发布时间】:2011-08-08 21:08:59
【问题描述】:

我想知道如何在通过对象定义的子函数中访问 jQuery 自定义函数。观察:

(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].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        }
    };
})(jQuery);

上述方法,使用$.notification ("update", data);不起作用,因为函数正在定义中。那么,如何在不重复代码的情况下访问上述功能呢?即编写一个函数只是为了更新,在method 变量之外,然后将该函数放在方法变量的update 索引中?提前谢谢你。 :3

【问题讨论】:

    标签: jquery function recursion user-defined-functions


    【解决方案1】:

    使用下面的行来执行它

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 2017-09-13
      • 1970-01-01
      • 2020-04-09
      • 1970-01-01
      相关资源
      最近更新 更多