Hacker News new | ask | show | jobs
by WebReflection 4152 days ago
or does it? You are passing arrays of arrays with a potentially random index position based convention that makes no sense to me at first read.

Is that how you pass on real-world code a generic person data around?

Is that how you don't use i18n for string and how you ignore occupations that starts with vowels?

Destructuring is nice as other new features in ES6 but abusing these just because there are there ... no, I don't think that's going to improve any code or any readability.

2 comments

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.
That's really nice. Is it possible to do the destructuring directly in the argument list?
Yes:

    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}`;
If you are passing JSON around, then arrays may be better for streams of data than json, with key/value ... if you are passing tabular data from one service to another, then you may very well pass an array you then want to destructure into an object.

For that matter, maybe even messagepack, protocol buffers , etc over 0mq or direct sockets... although straight json + gzip is pretty effective.