Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 5e0a2ca1e502c482e3e281d07a37558b75ce3308 1 parent d535f68
Scott González authored October 23, 2012

Showing 1 changed file with 8 additions and 3 deletions. Show diff stats Hide diff stats

  1. 11  ui/jquery.ui.widget.js
11  ui/jquery.ui.widget.js
@@ -142,9 +142,14 @@ $.widget.extend = function( target ) {
142 142
 	for ( ; inputIndex < inputLength; inputIndex++ ) {
143 143
 		for ( key in input[ inputIndex ] ) {
144 144
 			value = input[ inputIndex ][ key ];
145  
-			if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
146  
-				if ( $.isPlainObject( value ) && $.isPlainObject( target[ key ] ) ) {
147  
-					target[ key ] = $.widget.extend( {}, target[ key ], value );
  145
+			if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  146
+				// Clone objects
  147
+				if ( $.isPlainObject( value ) ) {
  148
+					target[ key ] = $.isPlainObject( target[ key ] ) ?
  149
+						$.widget.extend( {}, target[ key ], value ) :
  150
+						// Don't extend strings, arrays, etc. with objects
  151
+						$.widget.extend( {}, value );
  152
+				// Copy everything else by reference
148 153
 				} else {
149 154
 					target[ key ] = value;
150 155
 				}

0 notes on commit 5e0a2ca

Please sign in to comment.
Something went wrong with that request. Please try again.