Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Node.js기본
- 개발자
- PostgreSQL
- ServerSentEvent
- 실시간알림
- partitioning
- frontend
- EventSource
- node.js란
- Partition
- localStorage
- 성장기
- Lag
- mariadb
- 열공하자
- node.js
- 파티셔닝
- SSE
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[JS Level up][Ch1][데이터] 얕은 복사와 깊은 복사 본문
얕은 복사(Shallow copy)
// 얕은 복사
const user = {
name : 'Searchkim',
age : 29,
email : 'ejkim.Dev@gmail.com'
};
const copyUser = user; // copyUser와 user는 같은 메모리 주소를 바라봄
console.log(copyUser === user); // true
const asUser = Object.assign({}, user); // user를 {}에 복사해서 넣음 -> 새로운 메모리 할당
console.log(asUser === user); // false
const deUser = {...user}; // 전개 연산자 -> 새로운 메모리 할당
console.log(asUser === user); // false
user.age = 22;
console.log('user', user);
console.log('copyUser', copyUser);
console.log('asUser', asUser);
console.log('deUser', deUser);
깊은 복사(Deep copy)
lodash 패키지 설치
npm i lodash
import _ from 'lodash'
const user = {
name : 'Searchkim',
age : 29,
email : 'ejkim.Dev@gmail.com'
};
const copyUser = _.cloneDeep(user); // 깊은 복사
user.age = 22;
console.log('user', user);
console.log('copyUser', copyUser);
'파도파도 나오는 JavaScript' 카테고리의 다른 글
[JS Level up][Ch2][데이터 실습] Lodash 사용법 (0) | 2022.02.03 |
---|---|
[JS Level up][Ch2][데이터 실습] 가져오기, 내보내기 (0) | 2022.01.31 |
[JS Level up][Ch1][데이터] 불변성 (0) | 2022.01.31 |
[JS Level up][Ch1][데이터] 전개 연산자 (0) | 2022.01.31 |
[JS Level up][Ch1][데이터] 구조 분해 할당 (0) | 2022.01.31 |
Comments