개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.16 13:26

1. Object.assign(target, source) 사용법에 대해 알려주세요.

목록
  • Go매니아 5일 전 2025.04.16 13:26
  • 8
    1


2. Object.assign(target, source)에서 target과 source가 무엇인지 설명해주세요.
3. Object.assign(target, source)에서 source의 속성이 target에 복사되는 방식에 대해 알려주세요.

    댓글목록

    profile_image
    나우호스팅  5일 전



    1. Object.assign(target, source) 사용법에 대해 알려주세요.
    Object.assign(target, source)은 객체의 속성을 복사하는 메서드입니다. target 객체에 source 객체의 속성을 복사합니다. 예를 들어, 다음 코드를 살펴보겠습니다.

    #hostingforum.kr
    javascript
    
    let target = { a: 1, b: 2 };
    
    let source = { b: 3, c: 4 };
    
    
    
    Object.assign(target, source);
    
    console.log(target); // { a: 1, b: 3, c: 4 }
    
    


    2. Object.assign(target, source)에서 target과 source가 무엇인지 설명해주세요.
    target은 복사할 대상 객체입니다. source는 복사할 객체입니다. target 객체의 속성이 source 객체의 속성을 덮어씁니다.

    3. Object.assign(target, source)에서 source의 속성이 target에 복사되는 방식에 대해 알려주세요.
    Object.assign(target, source)에서 source의 속성이 target에 복사되는 방식은 다음과 같습니다.

    - target 객체의 속성이 source 객체의 속성을 덮어씁니다.
    - source 객체의 속성이 target 객체에 추가됩니다.
    - null 또는 undefined 값을 가진 속성은 target 객체에 추가되지 않습니다.

    예를 들어, 다음 코드를 살펴보겠습니다.

    #hostingforum.kr
    javascript
    
    let target = { a: 1, b: 2 };
    
    let source = { b: 3, c: 4, d: null };
    
    
    
    Object.assign(target, source);
    
    console.log(target); // { a: 1, b: 3, c: 4 }
    
    

    2025-04-16 13:27

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 13,263건 / 49 페이지

검색

게시물 검색