Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 915316x 589097x 326219x 326219x 326219x 1433352x 1254728x 1254728x 776238x 1254728x 326219x | /**
* Clones an object, returning a new object containing the same properties.
*
* @function
*
* @param {object} object The object to clone.
* @param {boolean} [deep=false] If true, all properties will be deep cloned recursively.
* @returns {object} The cloned object.
*/
function clone(object, deep) {
if (object === null || typeof object !== "object") {
return object;
}
deep = deep ?? false;
const result = new object.constructor();
for (const propertyName in object) {
if (object.hasOwnProperty(propertyName)) {
let value = object[propertyName];
if (deep) {
value = clone(value, deep);
}
result[propertyName] = value;
}
}
return result;
}
export default clone;
|