Object.assign()

Rick Waldron waldron.rick at gmail.com
Thu Oct 18 07:13:52 PDT 2012


On Thu, Oct 18, 2012 at 12:59 AM, Dmitry Soshnikov <
dmitry.soshnikov at gmail.com> wrote:

>
> On Oct 17, 2012, at 9:34 PM, Axel Rauschmayer wrote:
>
> Pardon, I missed and cannot find what is Object.assign(...), seems it's
> not from the latest draft. Is it just defining properties (via
> Object.defineProperty) on from a source to destination object? Like
> old-good Object.extend(...)?
>
>
> Explained here:
> https://github.com/rwldrn/tc39-notes/blob/master/es6/2012-09/sept-18.md
>
>
> I see, thanks.
>
> So, from what I see:
>
> 1. Source should not be the one. We should support many of sources to copy
> all them at once:
>
> Object.assign(dest, source1[, source2, ... sourceN])
>


I had originally hoped for this, but we reached consensus
on Object.assign(dest, source) to allow for a possible descriptor map param.

The pattern you're looking for can be achieved as....

[ defaults, options, overrides ].reduce(Object.assign, {});



>
> In addition:
>
> 2. If the last parameter is boolean, then it's created as
> includeNonEnumerable:
>
> Object.assign(desc, source1[, source2, ... sourceN, includeNonEnumerable);
>


Boolean parameters are a non-starter and would conflict with the desire to
have an optional third "default descriptor map" parameter.


Rick


>
> Example;
>
> Object.assign({a: 10}, {b: 20}, Object.defineProperties({}, {c: {value:
> 30}}), true); // {a: 10, b: 20, c: 30}
>
> Dmitry
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121018/b31aae90/attachment.html>


More information about the es-discuss mailing list