Live data from Hacker News

Emerging JavaScript pattern: multiple return values

loige.co

1–10 of 24 posts

Re: Emerging JavaScript pattern: multiple return values

#2
I 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

#4
post #3

Returning 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

#5
So 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.

Re: Emerging JavaScript pattern: multiple return values

#6
Please some admin (or you, Loige) add the "[2018]" tag since this is well established in 2020. It was "emerging to already there" back in 2018.

I 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

#7
post #2

I 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?

No one said to do this for performance

Re: Emerging JavaScript pattern: multiple return values

#8
post #4
post #3

Returning 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.

Sure, but I’ve been returning objects for 10+ years

Re: Emerging JavaScript pattern: multiple return values

#9

So 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.

Did we read the same article?

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.

Re: Emerging JavaScript pattern: multiple return values

#10
post #4

Earlier quoted context omitted.

Right and the article is from 2018. I have been using it for awhile.

Sure, but I’ve been returning objects for 10+ years

But you likely haven't been using destructuring assignment for 10+ years.
Post reply on HN