mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Widget: Fixed $.widget.extend() to never copy objects by reference.
This commit is contained in:
parent
d535f6869f
commit
5e0a2ca1e5
11
ui/jquery.ui.widget.js
vendored
11
ui/jquery.ui.widget.js
vendored
@ -142,9 +142,14 @@ $.widget.extend = function( target ) {
|
|||||||
for ( ; inputIndex < inputLength; inputIndex++ ) {
|
for ( ; inputIndex < inputLength; inputIndex++ ) {
|
||||||
for ( key in input[ inputIndex ] ) {
|
for ( key in input[ inputIndex ] ) {
|
||||||
value = input[ inputIndex ][ key ];
|
value = input[ inputIndex ][ key ];
|
||||||
if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
|
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
|
||||||
if ( $.isPlainObject( value ) && $.isPlainObject( target[ key ] ) ) {
|
// Clone objects
|
||||||
target[ key ] = $.widget.extend( {}, target[ key ], value );
|
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 {
|
} else {
|
||||||
target[ key ] = value;
|
target[ key ] = value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user