Skip to content
Permalink
Browse files

Widget: Fixed $.widget.extend() to never copy objects by reference.

  • Loading branch information...
scottgonzalez committed Oct 23, 2012
1 parent d535f68 commit 5e0a2ca1e502c482e3e281d07a37558b75ce3308
Showing with 8 additions and 3 deletions.
  1. +8 −3 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;
}

0 comments on commit 5e0a2ca

Please sign in to comment.
You can’t perform that action at this time.