[target, s1, s2, s3].reduce(function(p, c){
return Object.assign(p, c);
});
On Tue, Dec 17, 2013 at 5:06 PM, Claude Pache <claude.pache at gmail.com>wrote:
> Hello,
>
> Tonight, when playing with ES6’s new functions, I was wishing that
> `Object.assign` could accept several `source` objects:
>
> Object.assign(target, source1, source2, ...) // equivalent to
> `Object.assign(Object.assign(Object.assign(target, source1), source2), ...)`
>
> My use case: I have several objects, used as dictionaries, coming from
> different sources, and I want to merge them together. For example:
>
> c.prototype.exec = function(userParams) {
> var params = Object.assign({ method: "GET" }, this.defaultParams,
> userParams)
> // etc.
> }
>
> Any thoughts?
>
> —Claude
> _______________________________________________
> 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/20131217/5bb64a23/attachment.html>
domenic at domenicdenicola.com (2014-01-03T16:19:37.410Z)
[target, s1, s2, s3].reduce(function(p, c){ return Object.assign(p, c); }); On Tue, Dec 17, 2013 at 5:06 PM, Claude Pache <claude.pache at gmail.com>wrote: > Hello, > > Tonight, when playing with ES6’s new functions, I was wishing that > `Object.assign` could accept several `source` objects: > > Object.assign(target, source1, source2, ...) // equivalent to > `Object.assign(Object.assign(Object.assign(target, source1), source2), ...)` > > My use case: I have several objects, used as dictionaries, coming from > different sources, and I want to merge them together. For example: > > c.prototype.exec = function(userParams) { > var params = Object.assign({ method: "GET" }, this.defaultParams, > userParams) > // etc. > } > > Any thoughts? > > —Claude > _______________________________________________ > 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/20131217/5bb64a23/attachment.html>