diff --git a/tests/unit/widget/core.js b/tests/unit/widget/core.js index e36459f7226..1054bf09228 100644 --- a/tests/unit/widget/core.js +++ b/tests/unit/widget/core.js @@ -92,6 +92,18 @@ QUnit.test( "element normalization", function( assert ) { $.ui.testWidget(); } ); +QUnit.test( "contextless construction", function( assert ) { + assert.expect( 1 ); + var testWidget, + elem = $( "
" ); + + $.widget( "ui.testWidget", {} ); + testWidget = $.ui.testWidget; + + testWidget( {}, elem ); + assert.ok( true, "No crash" ); +} ); + QUnit.test( "custom selector expression", function( assert ) { assert.expect( 1 ); var elem = $( "
" ).appendTo( "#qunit-fixture" ); diff --git a/ui/widget.js b/ui/widget.js index 3b149f11ada..04daaa88309 100644 --- a/ui/widget.js +++ b/ui/widget.js @@ -77,7 +77,7 @@ $.widget = function( name, base, prototype ) { constructor = $[ namespace ][ name ] = function( options, element ) { // Allow instantiation without "new" keyword - if ( !this._createWidget ) { + if ( !this || !this._createWidget ) { return new constructor( options, element ); }