What should I use for namespace in jquery widgets?

I am reading the beginner's documentation on building plugins with jquery ui factory widget. Spaced Name Required:

 $.widget( 'dp.list', {


My question is: do you have a namespace? Are there conventions (buckets) for which namespace should my plugin belong? Is there a list somewhere or can I make whatever I want?


source to share

3 answers

A good start would be to look at the jQuery UI library. The names are very intuitive and meaningful. The name is the ui widget that will be created when the widget is instantiated.

The jQuery widget structure can be thought of as a tool to mimic OO functionality.

It provides a flexible framework for building complex stateful plugins with a consistent API. It is designed not only for plugins that are part of the jQuery UI, but for general consumption by developers who want to create object-oriented components without rethinking common frameworks. - http://wiki.jqueryui.com/w/page/12138135/Widget%20factory

The namespace can make sense if you have multiple modules and want to avoid collisions and also provide meaningful classification

$.widget('<module_name>.widgetName', {..prototype..} )



$.widget('cart.paymentProcess', {}) , $.widget('cart.shippingCalculator', {})
$.widget('catalog.productReviews',{}), $.widget('catalog.productPricing',{}) etc


I would also recommend reading these helpful questions to understand naming issues in jQuery widgets:

jQuery UI: how to call a widget function with its namespace

jQueryUI widget extension without conflicts



The namespace is personal. But:

  • The namespace should allow you to understand the "meaning" of the plugin
  • Try not to use something like "usethispluginforsearhthingsinsidethedom";)


The namespace is your way of identifying your plugin. Usually you want to use a few words that easily describe what your plugin does, but keep it pretty unique.

By describing your plugin, you briefly tell your users what they can expect from the plugin, but if the name is generic, you may come across another plugin by that name and this can cause problems.

You also don't want the ad name to not describe it, because then it's not clear what the plugin does.



All Articles