开发者

How I can extend a jquery plugin from another for overwrite methods?

I need extend a plugin from another, who is the best way for开发者_JAVA百科 it???

The extension will be overwrite methods and add any settings too.

I has a foo plugin that work well, now... I need extend another plugin bar from foo.

I write the following code, but is not work:

(function($) {
  var methods = {
    'onErrors': function (o, otherErrors) {
    }
  }
  $.extend(true, $[foo][bar].prototype, extensionMethods);
})(jQuery);

Now, how should be write a plugin extension??

Thanks


From the example code you included, my guess is you're trying to achieve what is shown in this answer.

If that's the case, then there are two issues in play here.

Firstly, you declared your list of methods as methods but then try to use it as extensionMethods.

Secondly, and more importantly, you seem to have misunderstood the example (or perhaps I misunderstood your requirements?). $.extend() will not allow you to create a new plugin bar from foo. You can however extend foo with additional methods. Like so:

(function($) {
   var extensionMethods = {
      // ....
   }
   $.extend($.fn.foo, extensionMethods);
})(jQuery);


Possibly look in to the jQuery Hook extension?

Though I'm not 100% sure what you're wanting to do. Some example code would be great (or better explain what you're trying to accomplish).

EDIT

Also see this post on the essence of function hooking.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜