source: trunk/termtv/js/clone.js@ 18292

Last change on this file since 18292 was 17409, checked in by tbretz, 11 years ago
Enable strict mode.
File size: 673 bytes
Line 
1'use strict';
2
3/**
4 * @public
5 *
6 * This clones all objects and arrays of the given element recursively.
7 * Functions are not cloned. This is sometimes necessary to fork
8 * the usage of information, beause otherwise javascript only passes
9 * references.
10 *
11 * @param {Object} src
12 * Source object to be cloned
13 *
14 * @returns {Object}
15 * The clone of the src object
16 */
17function clone(src)
18{
19 if (typeof(src) != 'object' || src===null)
20 return src;
21
22 var copy = typeof(src.length)!='undefined' ? new Array(src.length) : new Object();
23 for (var key in src)
24 copy[key] = typeof(src[key])=='object' ? clone(src[key]) : src[key];
25 return copy;
26}
Note: See TracBrowser for help on using the repository browser.