[jQuery] New object based on existing / Or understanding $.extend
Stretching my grasp of JavaScript here...
Please view source of this for context:
http://static.fusion.com.au/ollie/jquery/extend/test.html
$.fn.test = function() {
// Creating what I thought was a new object
var dupe = $.extend({},$.fn.test.orig);
// Adding item to array in my 'new' object
dupe.list.push('item');
// Success
console.log(dupe.list);
// but... I didn’t intend to add the list item to my original
console.log($.fn.test.orig.list);
return this;
};
$.fn.test.orig = {
list : []
};
I have created an object based on another object. (At least I thought
I did...)
When I attempt to manipulate my new object I discover the original
object has also been changed.
Therefore I presume my new object is actually a reference to the
original.
If not $.extend, how would I add the empty 'list' array (in reality a
bunch of properties) to my 'dupe' as a new separate object that can be
manipulated independent of the original?