Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend jQuery plugin/widget object to add method

I often see developers add methods to their own jquery Widget by extending the widget object. I'm not certain I really understand why and would appreciate if somebody could explain.

For example, the author(s) of jQuery UI Autocomplete Widget add 2 methods to their widget, why didn't they just have it in the original widget object?

like image 617
EasyCo Avatar asked Mar 23 '26 21:03

EasyCo


1 Answers

These utility functions don't access any of the widget's internal data, so they don't need to be within the widget function. The names are put into the widget's namespace to prevent polluting the global namespace.

like image 70
Barmar Avatar answered Mar 26 '26 09:03

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!