Widget: Allow instantiation without the new keyword.

This commit is contained in:
Scott González 2011-01-22 20:39:37 -05:00
parent 3a0b617bb4
commit 244eebe74d

View File

@ -37,7 +37,13 @@ $.widget = function( name, base, prototype ) {
$[ namespace ] = $[ namespace ] || {}; $[ namespace ] = $[ namespace ] || {};
$[ namespace ][ name ] = function( options, element ) { $[ namespace ][ name ] = function( options, element ) {
// allow instantiation without "new" keyword
if ( !this._createWidget ) {
return new $[ namespace ][ name ]( options, element );
}
// allow instantiation without initializing for simple inheritance // allow instantiation without initializing for simple inheritance
// must use "new" keyword (the code above always passes args)
if ( arguments.length ) { if ( arguments.length ) {
this._createWidget( options, element ); this._createWidget( options, element );
} }
@ -97,7 +103,7 @@ $.widget.bridge = function( name, object ) {
if ( instance ) { if ( instance ) {
instance.option( options || {} )._init(); instance.option( options || {} )._init();
} else { } else {
$.data( this, name, new object( options, this ) ); object( options, this );
} }
}); });
} }
@ -107,7 +113,13 @@ $.widget.bridge = function( name, object ) {
}; };
$.Widget = function( options, element ) { $.Widget = function( options, element ) {
// allow instantiation without "new" keyword
if ( !this._createWidget ) {
return new $[ namespace ][ name ]( options, element );
}
// allow instantiation without initializing for simple inheritance // allow instantiation without initializing for simple inheritance
// must use "new" keyword (the code above always passes args)
if ( arguments.length ) { if ( arguments.length ) {
this._createWidget( options, element ); this._createWidget( options, element );
} }