Search code examples
jqueryjquery-uiwidgetconstruction

jquery widget, _create or _init


Some jquery plugin extend widget use _create method, while others use _init method, can someone explain the differences between the two?

Also any guidance on when it is better to extend widget or directly extend jquery.fn?


Solution

  • The downside to extending widget (as opposed to $.fn) is that you create a dependency on jquery-ui which defines the widget "class". That dependency could be expensive for users of your plugin that don't also use jquery-ui.

    As far as _create vs _init goes, I'm pretty sure that _init came first and then in a recent revision they introduced and favor _create. I might be wrong about this, but I believe that _init is still supported. If it is then there shouldn't be any differences between the two.