Batch assignment functions

Rick Waldron waldron.rick at gmail.com
Wed Aug 15 14:38:48 PDT 2012


On Wed, Aug 15, 2012 at 5:30 PM, Brendan Eich <brendan at mozilla.org> wrote:

> Rick Waldron wrote:
>
>> As a result, I re-drafted Object.assign based on the real-world use
>> cases, but specifically does not attempt nested object property assignment
>> recursion. At this point I still believe that the deep nested assignement
>> case is strong enough to consider, but I'm not sure how to approach it. It
>> might warrant its own implicit "merge object properties whenever
>> possible"... Object.merge?
>>
>
> Object.merge, maybe -- but definitely do not want this muddled into
> assign/define or put/define or whatever those shallow-only names should be.


Agreed, which was the motivation for the three distinct APIs below


>
>
>  In summary, based on findings so far, I'd like to propose the following:
>>
>> In all cases, "target" refers to an object in the "dictionary of values"
>> or "bag of properties" sense. "source" can be any kind of object that has
>> own properties.
>>
>> Object.define( target, source ): defineProperties w/ sensible defaults
>> (w, e, c: true).
>>
>> Object.put( target, source ): is... "put"! (https://gist.github.com/**
>> 3350283 <https://gist.github.com/3350283>)
>>
>
> Some questions:
>
> 1. Why implicitly bind any function value?
>

The code in the gist should be regarded as a loose approximation of what I
think we should try to achieve — that said, it was actually just a modified
version of my API-ified implementation of Allen's define properties
operator :)


>
> 2. Ditto for get and set accessor functions?
>

Same  answer

>
> 3. Why Object.defineProperty if !(key in target)? Why not just always
> assign, since this is Object.put and not Object.define?


This part I was actually unsure of and it shows here; I made an assumption
that doesn't hold now that you've pointed it out and I've had to re-think
my motivation. So really, this can and should just be [[Put]]

I'll update the gist.

Rick


>
>
> /be
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120815/f4922055/attachment-0001.html>


More information about the es-discuss mailing list