3 ms·
You can destructure objects as well. So: const description = (nameAndOccupation) => { const { name: { first, last }, occupation } = nameAndOccupatio
by bzbarsky 12y ago
You can destructure objects as well.
So:
const description = (nameAndOccupation) => {
const { name: { first, last }, occupation } = nameAndOccupation;
return `${first} is a ${occupation}`;
}
description({ name: { first: "Reginald", last: "Brathwaite" }, occupation: "programmer" });
And this last _is_ in fact how real-world code would pass person data around. Your i18n points stand, of course.
- marxama 12y agoThat's really nice. Is it possible to do the destructuring directly in the argument list?
- peferron 12y agoYes: const description = ({name: {first, last}, occupation}) => `${first} is a ${occupation}`; Edit: just noticed that `last` is not used, so we can remove it from the destructuring: const description = ({name: {first}, occupation}) => `${first} is a ${occupation}`;