-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeep-clone.js
More file actions
38 lines (33 loc) · 803 Bytes
/
Copy pathdeep-clone.js
File metadata and controls
38 lines (33 loc) · 803 Bytes
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
32
33
34
35
36
37
38
'use strict'
import { runProcess } from '../utils/helpers.js';
//? The object, which one we would like to create a clone
const obj = {
id: 0,
name: 'Kazi Tajnur Islam',
email: 'tajnur007@gmail.com',
address: {
house: 'A/B, Mirpur',
city: 'Dhaka',
zipCode: 1234,
country: 'Bangladesh'
}
};
function deepCloneWithJSON() {
try {
JSON.parse(JSON.stringify(obj));
} catch (err) {
throw err;
}
}
function deepCloneWithStructuredClone() {
try {
structuredClone(obj);
} catch (err) {
throw 'Node version have to be v17.0.0 or higher to run this process';
}
}
export function runDeepCloneProcess() {
console.log('\nStarting deep clone test.....');
runProcess(deepCloneWithJSON, deepCloneWithStructuredClone);
console.log('Process finished!\n');
}