-3

I need extend a plugin from another, who is the best way for 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

yecid
  • 180
  • 3
  • 16

2 Answers2

1

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);
Community
  • 1
  • 1
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
0

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.

Community
  • 1
  • 1
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • Dear Brad, no... I not need a hook, I need extend a plugin from another plugin. – yecid Jun 03 '11 at 16:03
  • 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: [code] (function($) { var methods = { 'onErrors': function (o, otherErrors) { } } $.extend(true, $[foo][bar].prototype, extensionMethods); })(jQuery); [code] Now, how should be write a plugin extension?? – yecid Jun 03 '11 at 16:07
  • @Yecid: All depends on access levels/exposure of the methods. If you wrote the plugins, I would advise making them more modular so extending them is feasible (much like jQuery does with the `$.extend` ability) – Brad Christie Jun 03 '11 at 16:23