EasyCo
EasyCo

Reputation: 2036

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?

Upvotes: 3

Views: 162

Answers (1)

Barmar
Barmar

Reputation: 780724

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.

Upvotes: 1

Related Questions