]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Fixed $.widget.extend() to never copy objects by reference.
authorScott González <scott.gonzalez@gmail.com>
Tue, 23 Oct 2012 15:45:16 +0000 (11:45 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 23 Oct 2012 15:45:16 +0000 (11:45 -0400)
ui/jquery.ui.widget.js

index 59fd81b9e006b397c9fcdbf176a9d1dd00c8f561..05487f7edb87fc7d96d56a855e74ac8c1079e56c 100644 (file)
@@ -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;
                                }