diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-01-22 20:39:37 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-01-22 20:39:37 -0500 |
commit | 244eebe74dbc7bb35141e58e52ef9eaa21bd35f1 (patch) | |
tree | 9eb56513dc8eb8be7bf5bc6e69a9bf1720531633 /ui/jquery.ui.widget.js | |
parent | 3a0b617bb44565aacfa90c2ee20b293654d911c9 (diff) | |
download | jquery-ui-244eebe74dbc7bb35141e58e52ef9eaa21bd35f1.tar.gz jquery-ui-244eebe74dbc7bb35141e58e52ef9eaa21bd35f1.zip |
Widget: Allow instantiation without the new keyword.
Diffstat (limited to 'ui/jquery.ui.widget.js')
-rw-r--r-- | ui/jquery.ui.widget.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 1b00006a0..ea1826481 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -37,7 +37,13 @@ $.widget = function( name, base, prototype ) { $[ namespace ] = $[ namespace ] || {}; $[ 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 + // must use "new" keyword (the code above always passes args) if ( arguments.length ) { this._createWidget( options, element ); } @@ -97,7 +103,7 @@ $.widget.bridge = function( name, object ) { if ( instance ) { instance.option( options || {} )._init(); } else { - $.data( this, name, new object( options, this ) ); + object( options, this ); } }); } @@ -107,7 +113,13 @@ $.widget.bridge = function( name, object ) { }; $.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 + // must use "new" keyword (the code above always passes args) if ( arguments.length ) { this._createWidget( options, element ); } |