Suggestion: Destructuring object initializer.
Bob Myers
rtm at gol.com
Wed Feb 14 06:25:39 UTC 2018
Actually, I did understand what he said. I didn't respond because it was
obviously wrong.
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 did another test comparing `{...a, ...b}` and `Object.assign({}, a, b)`
and found that, at least on the platform I was comparing on, the
`Object.assign` alternative was actually a bit faster.
In any case, this optimization (skipping some lookups) is completely
separate from the optimization that Isiah was talking about.
With regard to the issue of the empty object inheriting a setter, my we're
really clutching at straws here. If you really are worried about someone
polluting the Object prototype with a setter, which is something any
optimization could account for anyway, then for the equivalent of `{...a,
...b}` please use `Object.assign(Object.create(null), a, b)`. NOW someone
please tell me what opportunities the engine has for optimizing the first
but not the second.
Bob
On Wed, Feb 14, 2018 at 11:16 AM, Raul-Sebastian Mihăilă <
raul.mihaila at gmail.com> wrote:
> Bob, it's not clear that you understood what Alexander said about the
> lookup. Object.assign contains 2 names. 'Object' needs to be looked up in
> all the execution contexts chain, starting with the current execution
> context, until the global Object function is found. Then the 'assign'
> property must be found on that object (it might have been deleted since it
> is configurable). The syntactic form doesn't require these lookups.
>
> Regarding `Object.assign({}, a, b)`, the empty object can inherit a
> setter which would be called.
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180214/ba23d909/attachment.html>
More information about the es-discuss
mailing list