Skip to content

Commit 30d468d

Browse files
committed
First draft for a $.Widget _super method
1 parent aa416fc commit 30d468d

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

tests/unit/widget/widget.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,21 @@ test(".widget() - overriden", function() {
165165
same(wrapper[0], $("<div></div>").testWidget().testWidget("widget")[0]);
166166
});
167167

168+
test("_super", function() {
169+
expect(2);
170+
$.widget("sup.parent", {
171+
log: function() {
172+
ok( this.called );
173+
}
174+
});
175+
$.widget("sup.child", $.sup.parent, {
176+
log: function() {
177+
this.called = true;
178+
ok( true );
179+
this._super("log");
180+
}
181+
});
182+
$("<div></div>").child().child("log");
183+
});
184+
168185
})(jQuery);

ui/jquery.ui.autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ $.widget( "ui.autocomplete", {
163163
.removeAttr( "aria-autocomplete" )
164164
.removeAttr( "aria-haspopup" );
165165
this.menu.element.remove();
166-
$.Widget.prototype.destroy.call( this );
166+
this._super( "destroy" );
167167
},
168168

169169
_setOption: function( key ) {

ui/jquery.ui.button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ $.widget( "ui.button", {
226226
this.buttonElement.removeAttr( "title" );
227227
}
228228

229-
$.Widget.prototype.destroy.call( this );
229+
this._super( "destroy" );
230230
},
231231

232232
_setOption: function( key, value ) {
@@ -358,7 +358,7 @@ $.widget( "ui.buttonset", {
358358
.end()
359359
.button( "destroy" );
360360

361-
$.Widget.prototype.destroy.call( this );
361+
this._super( "destroy" );
362362
}
363363
});
364364

ui/jquery.ui.widget.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ $.widget = function( name, base, prototype ) {
6262
namespace: namespace,
6363
widgetName: name,
6464
widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
65-
widgetBaseClass: fullName
65+
widgetBaseClass: fullName,
66+
base: base.prototype
6667
}, prototype );
6768

6869
$.widget.bridge( name, $[ namespace ][ name ] );
@@ -145,7 +146,11 @@ $.Widget.prototype = {
145146
},
146147
_create: function() {},
147148
_init: function() {},
148-
149+
150+
_super: function( method ) {
151+
this.base[ method ].apply( this, $.makeArray( arguments ).slice( 1 ) );
152+
},
153+
149154
destroy: function() {
150155
this.element
151156
.unbind( "." + this.widgetName )

0 commit comments

Comments
 (0)