ES6부터 객체와 배열을 다루는 방법과 객체와 배열 안에서 변수의 영역을 제한하는
방법을 다양하게 제공하기 시작.
구조 분해, 객체 리터럴 개선, 스레드 연산자가 이에 해당한다.
const sandwich = {
bread: "bread",
meat: "beef",
cheese: "cheese",
toppings: ["tomato", "onion"]
};
const {bread, meat} = sandwich;
console.log(bread,meat);
const lordify = regularPerson => {
console.log(`${regularPerson.firstname}`);
};
var regularPerson={
firstname: "ssook",
lastname: "choi"
};
lordify(regularPerson);
const lordify2 = ({firstname}) => {
console.log(`${firstname}`);
};
var regularPerson2={
firstname: "ssook",
lastname: "choi"
};
lordify2(regularPerson2);
const regularperson={
firstname: "ssook",
lastname: "choi",
person:{
firstname: "hi",
lastname: "hello"
}
};
const lorDify = ({person: {firstname}})=> {
console.log(`${firstname}`);
};
lorDify(regularperson);
const [firstname]=["ssook","sook","luel"];
console.log(firstname);
const [,,thirdname]=["ssook","sook","luel"];
console.log(thirdname);
const name = "탈락";
const elevation = 9738;
const funhike = {name, elevation};
console.log(funhike);
const name2 = "탈락";
const elevation2 = 9738;
const print=function(){
console.log(`${this.name2}의 높이는 ${this.elevation2}`)
};
const funhike2={name2,elevation2,print};
funhike2.print();
var skier = {
name: name,
sound: sound,
powderYell: function (){
var yell = this.sound.toUpperCase();
console.log(`${yell} ${yell} ${yell}!!!`)
},
speed: function (mph){
this.speed=mph;
console.log('속력',mph)
}
}
const skier2 = {
name: name,
sound: sound,
powderYell: function (){
var yell = this.sound.toUpperCase();
console.log(`${yell} ${yell} ${yell}!!!`)
},
speed(mph){
this.speed=mph;
console.log('속력',mph)
}
}
1.배열의 조합
const peaks = ["대청봉", "중청봉", "소청봉"];
const canyons = ["천불동계곡","가야동계곡"];
const seoraksan = [...peaks,...canyons];
console.log(seoraksan.join(','));
const peaks = ["대청봉", "중청봉", "소청봉"];
const canyons = ["천불동계곡","가야동계곡"];
const seoraksan = [...peaks,...canyons];
//const [last]=peaks.reverse(); 이렇게 하면 원래 배열도 뒤집어진다.
const [last]=[...peaks].reverse(); // 안 뒤집어진 채로 잘 나온다.
console.log(last);
console.log(peaks.join(', '));
function directions(...args) {
let [start, ...remaining] = args;
let [finish, ...stops] = remaining.reverse();
console.log(`${args.length}`);
console.log(`${start} 출발`);
console.log(`${finish} 목적지`);
console.log(`${stops.length}를 들립니다`);
}
directions(
"서울",
"수원",
"천안", "대전","대구","부산"
);
const morning ={
breakfast: "냠냠",
lunch: "냠냠냠"
};
const dinner = "냠냠?";
const meals = {
...morning,
dinner
};
console.log(meals);