-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
executable file
·31 lines (26 loc) · 866 Bytes
/
test.js
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
const deepClone = require('./index.js');
O.prototype.sayID = function() {
console.log('id is: ', this.id);
}
function O(id) {
this.m = null;
this.fn = () => {
console.log('\nhi, i am still alive!');
return true;
};
this.arr = [1],
this.id = id;
this.set = new Set();
}
const o = new O(123);
o.m = o;
const oCopy = deepClone(o);
o.arr.push(2);
o.set.add('set');
console.log('\noCopy structrue:', oCopy);
console.log('\nis oCopy.arr affected ?', oCopy.arr.includes(2));
console.log('\nis copy cycle reference successful ?', oCopy.m != o && oCopy.m === oCopy);
console.log('\nis fn functional ?', typeof oCopy.fn === 'function');
console.log('\nis proto left ?', typeof oCopy.sayID === 'function');
const oCopyWithProto = deepClone(o, true);
console.log('\nis proto left ?', typeof oCopyWithProto.sayID === 'function');