2019-09-29 18:29:54 +00:00
|
|
|
// Object property shorthand
|
|
|
|
|
|
|
|
const name = 'Jason'
|
|
|
|
const userAge = 38
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
name,
|
|
|
|
age: userAge,
|
|
|
|
location: 'Calgary'
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(user)
|
|
|
|
|
|
|
|
// Object destructuring
|
|
|
|
|
|
|
|
const product = {
|
|
|
|
label: 'Red notebook',
|
|
|
|
price: 3,
|
|
|
|
stock: 201,
|
|
|
|
salePrice: undefined,
|
|
|
|
rating: 4.2
|
|
|
|
}
|
|
|
|
|
|
|
|
// const label = product.label
|
|
|
|
// const stock = product.stock
|
|
|
|
|
|
|
|
// const {label:productLabel, stock, rating = 5} = product
|
|
|
|
// console.log(productLabel)
|
|
|
|
// console.log(stock)
|
|
|
|
// console.log(rating)
|
|
|
|
|
2019-10-10 17:56:26 +00:00
|
|
|
const transaction = (type, { label, stock = 0 } = {}) => {
|
2019-09-29 18:29:54 +00:00
|
|
|
console.log(type, label, stock)
|
|
|
|
}
|
|
|
|
|
|
|
|
transaction('order', product)
|