diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-10-23 11:45:16 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-10-23 11:45:16 -0400 |
commit | 5e0a2ca1e502c482e3e281d07a37558b75ce3308 (patch) | |
tree | ae2a78b259eaae7eaae5fde56037043ea308b021 /ui | |
parent | d535f6869fa252af4cddd8394b2a53100ed6618c (diff) | |
download | jquery-ui-5e0a2ca1e502c482e3e281d07a37558b75ce3308.tar.gz jquery-ui-5e0a2ca1e502c482e3e281d07a37558b75ce3308.zip |
Widget: Fixed $.widget.extend() to never copy objects by reference.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.widget.js | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 59fd81b9e..05487f7ed 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -142,9 +142,14 @@ $.widget.extend = function( target ) { for ( ; inputIndex < inputLength; inputIndex++ ) { for ( key in input[ inputIndex ] ) { value = input[ inputIndex ][ key ]; - if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { - if ( $.isPlainObject( value ) && $.isPlainObject( target[ key ] ) ) { - target[ key ] = $.widget.extend( {}, target[ key ], value ); + if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { + // Clone objects + if ( $.isPlainObject( value ) ) { + target[ key ] = $.isPlainObject( target[ key ] ) ? + $.widget.extend( {}, target[ key ], value ) : + // Don't extend strings, arrays, etc. with objects + $.widget.extend( {}, value ); + // Copy everything else by reference } else { target[ key ] = value; } |