Javascript
...(Object Spread Operator)스프레드 연산자
곽빵
2020. 1. 8. 14:49
let josh = {
field:'web',
language:'js'
}
let developer = {
nation:'korea',
...josh
}
console.log(developer)
[object Object] {
field: "web",
language: "js",
nation: "korea"
}
let developer2 = {
nation:'korea',
josh
}
console.log(develoer2);
[object Object] {
josh: [object Object] {
field: "web",
language: "js"
},
nation: "korea"
}
위 developer developer2를 출력해보면 developer는 스프레드 연산자를 사용해 마치 속성별로 묶어서
객체를 구성한듯한 모양이지만, 스프레드 연산자 없이 객체를 넣어버리면 말 그대로 객체안의 객체로 되버린다.
외에도, Spread 연산잔의 다양한 활용방법이 있다.
https://seongbeom.github.io/2017/02/08/uses-of-spread-operator.html
스프레드 연산자(...) 사용 예
스프레드 연산자(...) 사용 예 08 Feb 2017 몇가지 스프레드 연산자의 사용 예 정리겸. 6 Great Uses of the Spread Operator Merge Object Properties with the Spread Operator Apply 대체 기존 Function.prototype.apply 사용시 function doStuff (x, y, z) { } var args = [0, 1, 2]; doStuff.apply(null, ar
seongbeom.github.io
잘 정리해 두신분