If you have a reallyCool widget in your myns namespace, your $.widget() call would look like
- $.widget( "myns.reallyCool", {...
Note that in that line, what's on the left of the dot is the widget namespace, what's on the right is the widget name.
If you then do your namespace binds with the widget name:
- this.element.bind( "keydown.reallyCool", fn );
- this.element.bind( "keyup.reallyCool", fn );
the widget factory on destroy will automatically call
- this.element.unbind( ".reallyCool" );
Note that it does this based on the widget name (to the right of the dot) passed into $.widget, not what you used in the .bind()s. It will do this auto .unbind( ".widgetname" ) on the this.element and the this.widget() elements. See
http://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.widget.js#L164 . You'll still need to call such an unbind on any other elements you may have bound such events to.
I rather like the readability of the code above, with the widget name hardcoded and repeated, but if you prefer, you could do something like
- var ns = "myns",
- widgetName = "reallyCool";
- $.widget( ns + "." + widgetName, {...
- ...
- this.element.bind( "keydown." + widgetName, fn );
- this.element.bind( "keyup." + widgetName, fn );
or I guess you could use this.widgetName