Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I want a jQuery UI Widget to inherit from itself?

As of jQuery 1.9, a widget can inherit from itself. I couldn't find a real-world example of why this would be useful, and frankly the idea of inheriting from oneself breaks my brain. What is the purpose of this feature? What can I do using this feature that I couldn't do previously, or would've been much harder previously?

like image 512
RationalGeek Avatar asked Aug 24 '12 13:08

RationalGeek


1 Answers

The reason is to redefine the same widget. So, you add new capabilities to it, don't needing to extend it in another object.

In the example presented in the link that you sent:

$.widget("ui.dialog", $.ui.dialog, {
    close: function() {
        if (confirm( "Is it closing time?" )) {
            this._super("close");
        }
    }
});

After the execution of the code above, every dialog that is created will pop a confirm message when the user clicks in the close button and if s/he accepts it, it will close.

like image 172
davidbuzatto Avatar answered Oct 18 '22 09:10

davidbuzatto