Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let getPrice = (d, n) => {return {price: d+n};};
- let toppings = ['onions', 'tomato', 'lettuc', 'pickle'];
- let defaultFoodItem = {sauce: 'mild', hasCreameSause: 'yes', price: 2.34, toppings: [...toppings]};
- let taco = Object.assign({}, defaultFoodItem, {food: 'taco'}, getPrice(defaultFoodItem.price, 1.45));
- let fancyTaco = Object.assign({}, taco,
- Object.assign({}, {toppings: [...toppings, 'cheese', 'special sauce', 'vinegrate']}),
- getPrice(taco.price, 2.25)
- );
- console.log('defaultFoodItem', defaultFoodItem);
- console.log('taco', taco);
- console.log('fancyTaco', fancyTaco);
- /* Console:
- defaultFoodItem Object {sauce: "mild", hasCreameSause: "yes", price: 2.34, toppings: Array[4]}
- taco Object {sauce: "mild", hasCreameSause: "yes", price: 3.79, toppings: Array[4], food: "taco"}
- fancyTaco Object {sauce: "mild", hasCreameSause: "yes", price: 6.04, toppings: Array[7], food: "taco"}
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement