Suggestion: Destructuring object initializer.

T.J. Crowder tj.crowder at farsightsoftware.com
Wed Feb 14 09:24:58 UTC 2018


On Wed, Feb 14, 2018 at 7:03 AM, Raul-Sebastian Mihăilă <
raul.mihaila at gmail.com> wrote:
>
> On Wed, Feb 14, 2018 at 8:25 AM, Bob Myers <rtm at gol.com> wrote:
>>
>> For example, I did a quick test comparing `[1, 2]` and
>>`new Array(1, 2)` and found that performance was identical, in
>> spite of the claimed inefficiency supposedly introduced by the
>> need to look up `Array`.
>>
>
> I'm curious how you did that testing. Could you post is here?

FWIW: https://jsperf.com/literal-vs-new-array-in-nested-context

`new Array(x, y)` does seem to be nicely optimized. Interestingly, the
one-argument version (passing a non-number as the first argument to avoid
that weirdness in `new Array`) is hugely slower on Firefox. But presumably
that's because of the branch it has to take to check the type of the
parameter (which is something it dosen't share with `Object.assign` vs
spread). In the 2+ argument case, they're about the same, at least in that
test.

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180214/c2420647/attachment.html>


More information about the es-discuss mailing list