Day3(3.16)

ShinJuYong·2022년 3월 16일
0

camp

목록 보기
3/44
post-thumbnail

구조분해할당(SpreadOperator/RestParameter)

SpreadOperator

// 얕은복사
let profile1 = {
  name : 'a name',
  age : 99,
  school: 'bucheon'
}

let profile2 = profile1 // 이러면 두개는 동일한 메모리를 참조한다.
// 즉, profile2를 수정하면 profile1도 수정된다.
// SpreadOperator를 이용한 객체 깊은복사
let profile1 = {
  name : 'a name',
  age : 99,
  school: 'bucheon'
}

let profile2 = {
  ...profile1
}
// 두개는 각각의 메모리를 가지게 된다.
let profile1 = {
  name : 'a name',
  age : 99,
  school: 'bucheon',
  obj : {some:"thing"}
}

let profile2 = {
  ...profile1
}
// 이런식으로 복사하게되면 profile1.obj가 얕은 복사가 된다.
// 즉 profile1은 깊은복사가됐지만 obj는 여전히 메모리가 연결된 상태라는것이다.

// 깊은복사로 바꾸는법
// 1. JSON.stringify(profile1) -> 문자열로 바꾼다.
// 2. profile2에 JSON.parse를 통해서 stringify한것을 넣어 객체화 시킨다.

/* 사용예 */
profile2 = JSON.parse(JSON.stringify(profile1))

위의 깊은복사와 얕은복사는 Array(배열)에도 동일하게 적용된다.

위의 DeepCopy뿐만아니라
수많은 기능이 담긴 lodash라는 라이브러리가 있다.
로대쉬 알고쓰자!

REST Parameter

const child = {
	n1 : "1",
    n2 : "2",
  	deletethat : "me?"
}

const { n1, n2, ...rest } = child
// 앞의 두개를 제외한것들이 ...rest에 포함돼 복사된다.
// 원본은 남아있는다.

Http,api,graphql,rest

http 정리
api, rest, graphql 정리

Postman,Playground

rest API

postman , swagger

garphql API

Playground

알고리즘

WEEK2

WEEK2_DAY08
WEEK2_DAY09

0개의 댓글