请参阅插件中的插件对象

时间:2012-02-06 17:01:39

标签: javascript jquery oop plugins prototypal-inheritance

我正在尝试通过this访问插件,以便引用稍后在链中添加的方法。

$.fn.test = function(){

    console.log(this);
}

但是this指的是我用来调用插件的元素,而不是插件本身。

如何访问插件,以及附加到它的任何方法?

1 个答案:

答案 0 :(得分:0)

如果你想要jQuery对象,请使用$(this)

您也可以尝试将此插件添加到jQuery。

(function($){

    $.extend($.fn, {
        test: function(){
            //Plugin code here
            //here this will point to jQuery object
        }
    };
})(jQuery);