Emerging JavaScript pattern: multiple return values
1–10 of 24 posts
Re: Emerging JavaScript pattern: multiple return values
#2Re: Emerging JavaScript pattern: multiple return values
#3Re: Emerging JavaScript pattern: multiple return values
#4Returning an object and returning an array aren't exactly new concepts in Javascript? The only relatively-new part is destructuring assignment, but that's been around since 2015, since it was added in ES6.
I have been using it for awhile.
Re: Emerging JavaScript pattern: multiple return values
#5This is pretty hacky and it smells. it also won't work in languages like typescript (without losing the advantage of using it) which is frequently used.
Re: Emerging JavaScript pattern: multiple return values
#6I also missed generators from this list, which are the "official" (but a lot more complex than the ones showed here!) way of having multiple async returns:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re: Emerging JavaScript pattern: multiple return values
#7I don't understand what kind of stuff people build in React where performance implications of this sort is relevant. I'm building games where I loop through potentially thousands of objects 60 times a second and optimizations on that level still don't make any difference. It's always rendering that is the bottleneck. Shouldn't it be the same with React?
Re: Emerging JavaScript pattern: multiple return values
#8Returning an object and returning an array aren't exactly new concepts in Javascript? The only relatively-new part is destructuring assignment, but that's been around since 2015, since it was added in ES6.
Right and the article is from 2018. I have been using it for awhile.
Re: Emerging JavaScript pattern: multiple return values
#9So instead of returning a object, we stuff two values into an array and this grants us the advantage of saving a few extra characters. This is pretty hacky and it smells. it also won't work in languages like typescript (without losing the advantage of using it) which is frequently used.
I do absolutely not see the author advocating returning values in an array instead of an object, in fact, they seems to be saying the exact opposite? (starting with the array example, and then going to the object example afterwards)
The primary point of the article is the destructuring which makes the syntax much nicer.