-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
22 lines (22 loc) · 985 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
function test() {
"use strict";
let a = { b: { c: 4 }, d: { e: { f: 1 } } };
let g = Object.assign({}, a);
let h = JSON.parse(JSON.stringify(a));
console.log(JSON.stringify(g.d)); // { e: { f: 1 } }
g.d.e = 32;
console.log("g.d.e set to 32."); // g.d.e set to 32.
console.log(JSON.stringify(g)); // { b: { c: 4 }, d: { e: 32 } }
console.log(JSON.stringify(a)); // { b: { c: 4 }, d: { e: 32 } }
console.log(JSON.stringify(h)); // { b: { c: 4 }, d: { e: { f: 1 } } }
h.d.e = 54;
console.log("h.d.e set to 54."); // h.d.e set to 54.
console.log(JSON.stringify(g)); // { b: { c: 4 }, d: { e: 32 } }
console.log(JSON.stringify(a)); // { b: { c: 4 }, d: { e: 32 } }
console.log(JSON.stringify(h)); // { b: { c: 4 }, d: { e: 54 } }
let k = Object.create(h);
k.d.e = { j: 69 };
console.log(JSON.stringify(h)); // { b: { c: 4 }, d: { e: 54 } }
console.log(JSON.stringify(k)); // { b: { c: 4 }, d: { e: 54 } }
}
test();