Search code examples
javascriptjqueryjquery-uijquery-ui-widget-factory

To _destroy() or to destroy()?


I'm a little confused as to which _destroy or destroy method in a jQuery UI Widget to implement.

In this MSDN Widget Reference it says to implement destroy(), but in this Tutorial Plus reference it says to implement _destroy().

Both references say those methods should return the element to it's pre-widget state. So that part I understand, but why are there two versions of this method in the widget factory?


Solution

  • Read the docs from jQuery UI and not on MSDN

    http://wiki.jqueryui.com/w/page/12138135/Widget%20factory

    // Use the destroy method to clean up any modifications your widget has made to the DOM
    destroy: function() {
      // In jQuery UI 1.8, you must invoke the destroy method from the base widget
      $.Widget.prototype.destroy.call( this );
      // In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
    }
    

    });