ES6

katrina·2021년 12월 2일
0

Destructuring assignment

배열 해체 할당

let [,,third] = [‘red’,’white’,’orange’]
const arr = [1,2,3,4,5];
const [a, ...b] = arr; // a = 1, b = [2,3,4,5]
const [,,...c] = arr; // c = [3,4,5]
const [e=f,f] = [undefined,10] // f is not defined
let a = 10, b = 20;
[a,b] = [b,a]

객체 해체할당

const {
	device,
    device : {
    	createAt
    }
} =  {
	device : {
    	createdAt : '12',
        deviceId : '00'
        deviceType : 'desktop
    }
};

const {
	name : n,
    version : v = '6+',
    color : c = 'silver'
} = {
	name : 'phone',
    color : undefined
}

const {
	items : [,...products]
} = {
	items : [
    	{ name : 'test'},
        { name : 'test2'}
    ]
}

const getArea = ({width, height} = {width : 0,height:0}) => { return width + height}

function ({name, nickname = name}){..}

0개의 댓글