I'm a fairly new jQuery user looking to extend an existing jQuery plugin that does about 75% of what I need. I've tried to do my homework on this. I've checked out the following questions on stackoverflow:
I've read up on the extend method. However, all of thise homework has left me confused. I'm working with the fullcalendar plugin and need to modify some of the behavior as well as add new event hooks. Am I stuck with doing this in the plugin closure itself? Am I missing something obvious?
Ideally we would be able to separate our code from the plugin code to allow for a possible upgrade. Any help would be greatly appreciated, especially pointers on where I'm missing some information or opinions on whether the solutions already presented in other Stack Overflow questions make sense. To me they contradict each other and I'm still left confused.
I just had the same problem trying to extend jquery UI plugins, and here is the solution I found (found it through jquery.ui.widget.js):
hope this helps, please ask if you have any questions.
My approach in rewriting jQuery plugins has been to move methods and variables that need to be accessed to the options block and call the 'extend'
Example similar to Jared Scott`s answer, but making a copy of original object prototype gives the ability to call parent method:
jQuery Widget can be extended using jQuery Widget Factory.
Check out jQuery Documentation to learn more:
Widget Factory API
Extending Widgets with the Widget Factory
//
// using custom plugin
/// above written type of utils usually work of dom elements /////////////// custom utils
// access above util as
// this type of utils usually extend javascript
Ive found that with a lot of plugins the methods are protected/private (ie in the closures scope). If yo need to modify the functionality of the methods/functions then your out of luck unless youre willing to fork it. Now if you dont need to change any of these methods/functions then you can use
$.extend($.fn.pluginName, {/*your methods/properties*/};
Another thing ive ended up doing before is simply using the plugin as a property of my plugin instead of trying to extend it.
What it all really comes down to is how the plugin you want to extend is coded.