Hacker News new | ask | show | jobs
by trgn 69 days ago
> Non-primitives are always pass-by-reference.

it's a good thing. pass objects by reference.

> Is there a behavior you think is unique to destructuring?

depending on exact syntax, will collect values in another array or object. it's often used as the mirror-pattern of using named variables, which allocates an object for each function call.

in isolation these are not inherently wrong, at scale they start to add up. and should not be used in tight loops.

1 comments

> pass objects by reference.

It’s not an option. That’s how JS must behave.

> depending on exact syntax, will collect values in another array or object

Not in JS. Maybe you are referring to rest syntax? That is not specific to destructuring i.e. functions accept rest parameters.

> which allocates an object for each function call.

No, in JS non-primitives MUST be pass by reference.

You're being pedantic and doing gotcha argumenting.

Pass objects by ref, I said that to underscore its better than create new objects. I get it, its the only way, but theyre still passed by ref.

Yes, [a,b,...rest] =... is restructuring and creates new object.

Named params create new objects, it's better to pass args individually, the ref creation under the hood is not comparibly impactful.