Question

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?

Was it helpful?

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
}

});

OTHER TIPS

Just to clarify (and based on this):

In jQuery UI 1.8 your widget should look like so:

$.widget( "demo.widget", {
    destroy: function() {
        // Invoke the base destroy method
        $.Widget.prototype.destroy.call( this );
        // Perform widget-specific cleanup
        ...
    }
});

and in jQuery UI 1.9, like so:

$.widget( "demo.widget", {
    _destroy: function() {
        // Perform widget-specific cleanup
        ...
    }
});

That is, in 1.9 you shouldn't define a (public) destroy method; define _destroy instead; and within it there is no need to call the base call destructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top