aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2007-08-21 04:42:31 +0000
committerJohn Resig <jeresig@gmail.com>2007-08-21 04:42:31 +0000
commite112e6b04d1736d3a847d44b96f7178175e17a15 (patch)
tree8002efee55d2a982fc9f262a8ba3e01b6ebe589d /src
parent8cf5d2df19d918bb84f4c59bc4346c215fbfaf88 (diff)
downloadjquery-e112e6b04d1736d3a847d44b96f7178175e17a15.tar.gz
jquery-e112e6b04d1736d3a847d44b96f7178175e17a15.zip
Make deep .extend() an optional argument - it will go deep if you pass in an boolean as the first argument (fixed bug #1028).
Diffstat (limited to 'src')
-rw-r--r--src/ajax/ajax.js4
-rw-r--r--src/jquery/coreTest.js2
-rw-r--r--src/jquery/jquery.js10
3 files changed, 11 insertions, 5 deletions
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js
index 4f0b2e8fd..d9b3a3d8b 100644
--- a/src/ajax/ajax.js
+++ b/src/ajax/ajax.js
@@ -434,7 +434,7 @@ jQuery.extend({
* @cat Ajax
*/
ajaxSetup: function( settings ) {
- jQuery.extend( jQuery.ajaxSettings, settings );
+ jQuery.extend( true, jQuery.ajaxSettings, settings );
},
ajaxSettings: {
@@ -575,7 +575,7 @@ jQuery.extend({
ajax: function( s ) {
// Extend the settings, but re-extend 's' so that it can be
// checked again later (in the test suite, specifically)
- s = jQuery.extend(s, jQuery.extend({}, jQuery.ajaxSettings, s));
+ s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
// if data available
if ( s.data ) {
diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js
index ff8909c8b..312bc3ce1 100644
--- a/src/jquery/coreTest.js
+++ b/src/jquery/coreTest.js
@@ -680,7 +680,7 @@ test("$.extend(Object, Object)", function() {
isObj( settings, merged, "Check if extended: settings must be extended" );
isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
- jQuery.extend(deep1, deep2);
+ jQuery.extend(true, deep1, deep2);
isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 797280e07..a79b2e6b2 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -1256,7 +1256,13 @@ jQuery.fn = jQuery.prototype = {
*/
jQuery.extend = jQuery.fn.extend = function() {
// copy reference to target object
- var target = arguments[0] || {}, a = 1, al = arguments.length;
+ var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;
+
+ // Handle a deep copy situation
+ if ( target.constructor == Boolean ) {
+ deep = true;
+ target = arguments[1] || {};
+ }
// extend jQuery itself if only one argument is passed
if ( al == 1 ) {
@@ -1276,7 +1282,7 @@ jQuery.extend = jQuery.fn.extend = function() {
continue;
// Recurse if we're merging object values
- if ( typeof prop[i] == 'object' && target[i] )
+ if ( deep && typeof prop[i] == 'object' && target[i] )
jQuery.extend( target[i], prop[i] );
// Don't bring in undefined values