-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimmutability.js
91 lines (58 loc) ยท 1.39 KB
/
immutability.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ์์ํ์
์ ๋ณ๊ฒฝ ๋ถ๊ฐ๋ฅํ ๊ฐ์ด๋ค. ์ฌํ ๋น์ ๊ฐ๋ฅ
// boolean, null, undefined, number, string, symbol
// ์์ํ์
์ด์ธ์ ๋ชจ๋ ๊ฐ์ ๊ฐ์ฒด ํ์
, ๊ฐ์ฒด ํ์
์ ๋ณ๊ฒฝ ๊ฐ๋ฅํ ๊ฐ์ด๋ค.
var str = "hello";
str = "world";
//hello์ world ๋ชจ๋ ๋ฉ๋ชจ๋ฆฌ์ ์กด์ฌ
var statement = "I am an immutable value";
var otherStr = statement.slice(1,4);
console.log(statement);
console.log(otherStr);
var arr = []
console.log(arr.length);
var v2 = arr.push(2);
console.log(arr.lenth);
var user = {
name: "Lee",
adress: {
city: 'Seoul'
}
};
var myName = user.name;
user.name = "Kim";
console.log(myName);
myName = user.name;
console.log(myName);
var user1 = {
name: "Lee",
address: {
city: "Seoul"
}
};
var user2 = user1;
user2.name = "Kim";
console.log(user1.name);
console.log(user2.name);
const obj = { a: 1 };
const copy = Object.assign({}, obj);
console.log(copy);
console.log(obj == copy);
const o1 = { a: 1};
const o2 = { b: 2};
const o3 = { c: 3};
const merge1 = Object.assign(o1, o2, o3);
console.log(merge1);
console.log(o1); // ํ๊ฒ ๊ฐ์ฒด๊ฐ ๋ณ๊ฒฝ
const o4 = { a: 1};
const o5 = { b: 2};
const o6 = { c: 3};
const merge2 = Object.assign({}, o4, o5, o6);
console.log(merge2);
console.log(o4);
const user1 = {
name: 'Lee',
address: {
city: "Seoul"
}
};
const user2 = Object.assign({}, user1);