고슴맨쉬
망치와 공(空)
고슴맨쉬
  • 분류 전체보기 (155)
    • 💡 UXUI (4)
      • UXUI (2)
      • UI (2)
      • UX (0)
    • 🟨 JavaScript (66)
      • 개념 (42)
      • 정리 (2)
      • 문제풀기 (프로그래머스, 코딩애플) (15)
      • 응용하여 자동화or문제해결하기 (2)
      • 기타 (5)
    • ⚛️ React (49)
      • 개념 (27)
      • 개념(Redux) (3)
      • 정리 (4)
      • 문제풀기 (코딩애플: React) (15)
    • 📘 TypeScript (10)
      • 개념 (8)
      • 문제풀기 (코딩애플) (2)
    • 🌐 HTML,CSS (18)
      • 실무에서 자주 발생한 오류들 (10)
      • 뒤늦게 알아서 뼈아픈 유용한 CSS (6)
      • 기타 자주 쓰는 CSS (2)
    • 💻 CS (8)
      • CS (5)
      • 정규표현식 (2)
      • Git,Github (1)

태그

  • CSS
  • 프로그래머스
  • array
  • 코딩애플
  • class
  • 오류
  • UXUI
  • CS
  • useEffect
  • json
  • object
  • JavaScript
  • 삼항연산자
  • state
  • redux
  • TypeScript
  • Props
  • react
  • axios
  • Ajax
전체 방문자
오늘
어제
hELLO · Designed By 정상우.
고슴맨쉬

망치와 공(空)

🟨 JavaScript/개념

[mdn, 드림코딩 외] 객체(Object)와 프로퍼티(property) (2) : 생성/수정과 cloning

2022. 5. 31. 12:29

https://sunshineyellow.tistory.com/17?category=1037372 

 

[코딩앙마 외] 객체(Object)와 프로퍼티(property)

객체(Object) key와 value로 이루어질 수 있다. 1. 함수표현식 const goodCoder = function(name, age, coding) { name : 'Noran', age : 20, coding : function(){ console.log('화이팅!'); } } name : 'Noran',..

sunshineyellow.tistory.com

https://sunshineyellow.tistory.com/18?category=1037372 

 

[코딩앙마 외] 객체 리터럴과 객체 접근법, 그리고 생성자 함수

객체를 생성하는 방법에는 두 가지가 있다. 객체 리터럴 생성자 함수 단 하나의 객체만을 생성할 때는 직관적이고 간편한 객체 리터럴을 사용하고, 같은 객체를 대량생산할 때는 생성자함수를

sunshineyellow.tistory.com

 

위 글을 보충해 객체 프로퍼티의 생성과 수정, 삭제에 대해 다룬다.


생성

클래스의 객체 생성

const noran = new Goodcoder('noran', 20);

클래스 없이 객체 생성

const noran = { name : 'noran', age : 20 };

수정

key 추가

noran.hasjob = true;

key 삭제

delete noran.hasjob;

cloning

아래의 경우 coder1과 coder2의 value가 같이 바뀐다.

const coder1 = { name : 'noran', age : 20 };
const coder2 = coder1;
coder2.name = 'paran';

console.log(coder1); //'paran'

properties 복사하기 (예전버전)

const coder3 = {};
for (key in coder1) {
  coder3[key] = coder1[key];
}

console.log(coder3); //{name : 'noran', age : 20}

properties 복사하기 (신버전)

const coder4 = {};
Object.assign(coder4, coder1);

console.log(coder4); //{name : 'noran', age : 20}

위는 아래처럼 정리될 수 있다.

const coder4 = Object.assign({}, coder1);

출처 : 드림코딩 https://www.youtube.com/@dream-coding / MDN https://developer.mozilla.org/ko

저작자표시 비영리 동일조건 (새창열림)

'🟨 JavaScript > 개념' 카테고리의 다른 글

[mdn, 드림코딩 외] 배열(array) : 배열에의 접근과 looping  (0) 2022.05.31
[mdn, 드림코딩 외] 객체(Object)와 프로퍼티(property) (3) : computed properties  (0) 2022.05.31
[mdn, 드림코딩 외] 객체지향 (5) : instanceOf 연산자  (0) 2022.05.25
[mdn, 드림코딩 외] 객체지향 (4) : 클래스의 상속 (sub classing)  (0) 2022.05.25
[mdn, 드림코딩 외] 객체지향 (3) : 정적 속성과 메소드(static properties and methods)  (0) 2022.05.04
    '🟨 JavaScript/개념' 카테고리의 다른 글
    • [mdn, 드림코딩 외] 배열(array) : 배열에의 접근과 looping
    • [mdn, 드림코딩 외] 객체(Object)와 프로퍼티(property) (3) : computed properties
    • [mdn, 드림코딩 외] 객체지향 (5) : instanceOf 연산자
    • [mdn, 드림코딩 외] 객체지향 (4) : 클래스의 상속 (sub classing)
    고슴맨쉬
    고슴맨쉬
    부수되 집착하지 않고, 이해하되 머무르지 않기

    티스토리툴바