const restaurant = {
name: 'Classico Italiano',
location: 'Via Angelo Tavanti 23, Firenze, Italy',
categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],
mainMenu: ['Pizza', 'Pasta', 'Risotto'],
order: function(starterIndex, mainIndex) {
return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]];
}
orderDelivery : function ({starterIndex, mainIndex, time, address}) {
console.log(`order received ${this.starterMenu[starterIndex]} and
${this.mainMenu[mainIndex]}`)
}
openingHours: {
thu: {
open: 12,
close: 22,
},
fri: {
open: 11,
close: 23,
},
sat: {
open: 0, // Open 24 hours
close: 24,
},
},
};
restaurant.orderDelivery({
time: '22:30'
address: 'Via del Sole, 21'
mainIndex: 2,
starterIndex: 2,
})
const {name, openingHours, categories} = restaurant;
console.log(name, openingHours, categories);
const {name: restaurantName, openingHours: hours, categories: tags}
console.log(restaurantName, hours, tags)
// default value
const { menu = [], starterMenu: starters = []} = restaurant;
console.log(menu, starters);
// Mutating variables
let a = 111;
let b = 999;
const obj = {a: 23, b: 7, c: 12};
({a, b} = obj);
// wrapping 필요
console.log(a, b);
// nested objects
const {fri: {open: o, close: c}} = openingHours;
console.log(o, c);
// 11, 23
'공부자료 > 자바스크립트' 카테고리의 다른 글
브라우저인지 확인하는 조건문 (0) | 2021.12.04 |
---|---|
코드캠프 4기 - 11월 15일 (0) | 2021.11.15 |
Section 9: Data Structures, ModernOperators and Strings - Destructuring Arrays (0) | 2021.10.28 |
ddays 계산하기 (0) | 2021.09.29 |
Coding Challenge - sum by looping (0) | 2021.09.20 |