Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. let getPrice = (d, n) => {return {price: d+n};};
  2. let toppings = ['onions', 'tomato', 'lettuc', 'pickle'];
  3. let defaultFoodItem = {sauce: 'mild', hasCreameSause: 'yes', price: 2.34, toppings: [...toppings]};
  4. let taco = Object.assign({}, defaultFoodItem, {food: 'taco'}, getPrice(defaultFoodItem.price, 1.45));
  5. let fancyTaco = Object.assign({}, taco,
  6. Object.assign({}, {toppings: [...toppings, 'cheese', 'special sauce', 'vinegrate']}),
  7. getPrice(taco.price, 2.25)
  8. );
  9.  
  10. console.log('defaultFoodItem', defaultFoodItem);
  11. console.log('taco', taco);
  12. console.log('fancyTaco', fancyTaco);
  13.  
  14. /* Console:
  15. defaultFoodItem Object {sauce: "mild", hasCreameSause: "yes", price: 2.34, toppings: Array[4]}
  16. taco Object {sauce: "mild", hasCreameSause: "yes", price: 3.79, toppings: Array[4], food: "taco"}
  17. fancyTaco Object {sauce: "mild", hasCreameSause: "yes", price: 6.04, toppings: Array[7], food: "taco"}
  18. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement