Thread:Mathmagician/@comment-3508190-20120504092551/@comment-4674838-20120508040343

Do you ever use $.extend ?

I haven't been able to find good documentation on it -- for that matter, I'm not even sure if it's a default JavaScript function, if it's in jQuery, or what. Do you ever use this / can you shed some light on it's behavior for me? Here's a test I set up -- can you explain why the behavior is so different?

var TVsettings = { on: false, volume: 10 } var newSettings = { on: true, channel: "Cartoon Network" } var override1; var override2 = 0; var override3 = {}; var override4; var override5; var override6;

// Output: override1 = undefined $.extend( override1, TVsettings, newSettings ); console.log('override1 = ' + override1);

// Output: override2 = 0 $.extend( override2, TVsettings, newSettings ); console.log('override2 = ' + override2);

// This call has the behavior I want // Output: override3 = [object Object]  on = true   volume = 10   channel = Cartoon Network $.extend( override3, TVsettings, newSettings ); console.log('override3 = ' + override3 + '  on = ' + override3.on + '   volume = ' + override3.volume + '   channel = ' + override3.channel);

// I don't understand this one at all... // Output: override4 = function (a,b){return new e.fn.init(a,b,h)} override4 = $.extend( newSettings ); console.log('override4 = ' + override4);

// If override5 was undefined, why is it now an object (and what's inside the object)? This isn't what happened to override1. // Output: override5 = [object Object] $.extend( override5 ); console.log('override5 = ' + override5);

// What does $.extend with no parameters do? // Output: override6 = [object Object] override6 = $.extend; console.log('override6 = ' + override6);