Editing Cloning an Object This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) There is no quick and easy facility for cloning an object, Some people recommend using JQuery.extend others JSON.parse/stringify http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object If you want the fastest possible clone function. I would personally anticipate the data structure of your object and write a custom clone to handle it. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script src="//underscorejs.org/underscore-min.js"></script> <script> var oldObject = { a: 1, b: 2, c: 3, d: 4, e: 5, f: function() { return 6; }, g: [7, 8, 9] }; var i = 1000; while (i--) oldObject[Math.random()] = i; function clone(obj) { var target = {}; for (var i in obj) { if (obj.hasOwnProperty(i)) { target[i] = obj[i]; } } return target; } var extend = function(source, target) { var keys = Object.keys(source), i = keys.length, target = target || {}; while (i--) { target[keys[i]] = source[keys[i]]; } return target; } var fork = function(source) { var objmap = new Map(), targetOut = {__proto__: source.__proto__}, target, stack = {0: {source: source, target: targetOut}}, sp = 0, ss = 1, keys, key, j, scope, tmp; while ((scope = stack[sp++])) { keys = Object.keys(scope.source); j = keys.length; while (j--) { source = scope.source[key = keys[j]]; if (source !== null && source === Object(source)) { if ((tmp = objmap.get(source))) { scope.target[key] = tmp; } else { scope.target[key] = target = {__proto__: source.__proto__}; stack[ss++] = {source: source, target: target}; objmap.set(source, target); } } else { scope.target[key] = source; } } delete stack[sp - 1]; } target = source = stack = keys = key = scope = null; return targetOut; }; Object.defineProperties(Object, { 'extend': { 'configurable': true, 'enumerable': false, 'value': function extend(what, wit) { var extObj, witKeys = Object.keys(wit); extObj = Object.keys(what).length ? Object.clone(what) : {}; witKeys.forEach(function(key) { Object.defineProperty(extObj, key, Object.getOwnPropertyDescriptor(wit, key)); }); return extObj; }, 'writable': true }, 'clone': { 'configurable': true, 'enumerable': false, 'value': function clone(obj) { return Object.extend({}, obj); }, 'writable': true } }); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code var newObject = jQuery.extend(true, {}, oldObject); Test 2 Title Async (check if this is an asynchronous test) Code var newObject = JSON.parse(JSON.stringify(oldObject)); Test 3 Title Async (check if this is an asynchronous test) Code var newObject = jQuery.extend({}, oldObject); Test 4 Title Async (check if this is an asynchronous test) Code var newObject = clone(oldObject); Test 5 Title Async (check if this is an asynchronous test) Code var newObject = Object.clone(oldObject); Test 6 Title Async (check if this is an asynchronous test) Code var newObject = fork(oldObject); Test 7 Title Async (check if this is an asynchronous test) Code var newObject = extend(oldObject); Test 8 Title Async (check if this is an asynchronous test) Code var newObject = _.clone(oldObject); Test 9 Title Async (check if this is an asynchronous test) Code var newObject = _.extend({}, oldObject);