Search code examples
jquerywidgetextend

What is the way to extend a widget?


I would like to ask what is best way if we want to modify or extend part of existing jquery widget (like datepicker, data tables)?

I'm not really sure whether it is possible to apply kind of inheritance concept or would it just good if modify the original one?


Solution

  • The most important factor to answer such a question is what are your future expectations / requirements.

    Since you're question is about modules that are not specifically designed to be extended, they don't adhere to rules that support such usage. That means future versions might change anything from internal behavior all the way up to method / propery / event names.

    It makes little difference if you choose to modify existing code or extend it through inheritance as long as you don't care for future versions. Just pick the easier route (Of course considering all legal matters).

    If you do care for future versions, it might be tempting to choose an inheritance based solution so that future updates to the inherited module might be "transparent" to your extension but that's where the risk lies. If you don't force yourself to fully review what has changed, you'd never know if things still work as you intended.

    On the other hand choosing to modify existing code means any future version requires doing the same modifications all over again, but it forces you to validate it makes sense.