Skip to content

Commit ee88a56

Browse files
committed
Widget: Added ability to use $.widget() to create extensions. Fixes #6937 - Widget: Allow redefining a widget to create extensions.
1 parent ed49033 commit ee88a56

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tests/unit/widget/widget_core.js

+21
Original file line numberDiff line numberDiff line change
@@ -821,4 +821,25 @@ test( "auto-destroy - .detach()", function() {
821821
$( "#widget" ).testWidget().detach();
822822
});
823823

824+
test( "redefine", function() {
825+
expect( 4 );
826+
$.widget( "ui.testWidget", {
827+
method: function( str ) {
828+
strictEqual( this, instance, "original invoked with correct this" );
829+
equal( str, "bar", "original invoked with correct parameter" );
830+
}
831+
});
832+
var ctor = $.ui.testWidget;
833+
$.widget( "ui.testWidget", $.ui.testWidget, {
834+
method: function( str ) {
835+
equal( str, "foo", "new invoked with correct parameter" );
836+
this._super( "method", "bar" );
837+
}
838+
});
839+
840+
var instance = new $.ui.testWidget();
841+
instance.method( "foo" );
842+
equal( $.ui.testWidget, ctor, "constructor did not change" );
843+
});
844+
824845
}( jQuery ) );

ui/jquery.ui.widget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $.widget = function( name, base, prototype ) {
3636
};
3737

3838
$[ namespace ] = $[ namespace ] || {};
39-
$[ namespace ][ name ] = function( options, element ) {
39+
$[ namespace ][ name ] = $[ namespace ][ name ] || function( options, element ) {
4040
// allow instantiation without "new" keyword
4141
if ( !this._createWidget ) {
4242
return new $[ namespace ][ name ]( options, element );

0 commit comments

Comments
 (0)