Take the 2-minute tour ×

Ok, I'm having a slight bit of confusion writing my own jQuery UI widget plugins. The problem lies in the destroy function. In the docs, it says to put the default destroy first then write other things particular to the widget after it.

// now do other stuff particular to this widget

See http://jqueryui.com/docs/Developer_Guide

However in their example scripts (those being the actual pluings for jQuery Ui released code, does it the opposite. The

$.Widget.prototype.destroy.apply(this, arguments);

is at the end of the function. See http://dev.jqueryui.com/browser/trunk/ui/jquery.ui.progressbar.js (and all of the other built in widgets as well)

So which is it? The way the current widgets are written, or by the explanation in the code comment in the Developer_Guide?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I would personally put it at the end, in case anything crazy happens, but make sure anything you've created gets destroyed, then let the base methods do their work. From a practical standpoint?

It doesn't matter

It's just a matter of taste, and even in the 2 examples you linked, the taste of the developers writing them differed (or changed over time)...not a big enough issue for the documentation to be consistent.

Disclaimer: Opinion here!
Usually in cases like this, I think it's safer to stay with the convention of the code instead of the documentation. You're actively running the code in your browser, it's passing the jQuery unit tests, it's what's running...not the documentation which may or may not be accurate or outdated. I know I'm guilty of this, and that I'm not alone...I don't update the documentation all that often, not near as often as I refactor/improve the code at least :)

share|improve this answer

Your Answer


