Skip to content

Instantly share code, notes, and snippets.

@kopasetik
Last active February 8, 2016 21:45
Show Gist options
  • Save kopasetik/804c2976a48a7b6eed19 to your computer and use it in GitHub Desktop.
Save kopasetik/804c2976a48a7b6eed19 to your computer and use it in GitHub Desktop.
Javascript function destructuring
// function destructuring
const eat_pizza_picky_style = ({dough, sauce, meat}) => {
console.log('For this pizza, Whiskers only eats the '
+ dough + ', ' + sauce + ', and ' + meat
+ '. It picks everything else off!')
}
const pepperoni_pizza = {
cheese: 'mozzarella',
dough: 'white flour dough',
meat: 'pepperoni',
sauce: 'canned tomato sauce',
veggies: 'peppers',
}
const healthier_pizza = {
dough: 'whole grain dough',
meat: 'chicken',
sauce: 'alfredo sauce',
veggies: 'peppers',
cheese: 'swiss'
}
const northwest_pizza = {
dough: 'sourdough',
meat: 'salmon',
sauce: 'dijon mustard',
veggies: 'peppers',
seasoning: 'dill'
}
eat_pizza_picky_style(pepperoni_pizza)
//=> For this pizza, Whiskers only eats the white flour dough,
//=> canned tomato sauce, and pepperoni. It picks everything else off!
eat_pizza_picky_style(healthier_pizza)
//=> For this pizza, Whiskers only eats the whole grain dough,
//=> alfredo sauce, and chicken. It picks everything else off!
eat_pizza_picky_style(northwest_pizza)
//=>For this pizza, Whiskers only eats the sourdough, dijon mustard,
//=> and salmon. It picks everything else off!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment