Batch assignment functions

David Bruant bruant.d at gmail.com
Wed Aug 15 14:39:11 PDT 2012


Le 15/08/2012 21:42, Rick Waldron a écrit :
> Recently, Allen produced a strawman proposal[0][1] for the "object
> define properties" operator, which was designed to provide syntax that
> differentiated semantics of define vs. assign. Towards the end of the
> thread, IIRC, Brendan suggested some new Object functions:
> Object.define() and Object.assign().[2]
>
> I spent time over the weekend preparing common use cases for batch
> assignment based on real world examples from jQuery[3], Dojo[4],
> Node.js[5] and Lodash (an improved Underscore)[6][7] (With all due
> respect, Prototype is no longer considered a relevant library for use
> in modern day web development). Initially, I assumed that the jQuery
> "deep extend" was the common case and drafted an attempt at handling
> "nested assignment" or "deep extending". Off-list, Dave Herman
> reminded me that there is no way to know what the user _actually_
> wants with regard to nested object properties:
>
>
> 1. Target property does not exist: define source value
> 2. Target property exists, its value is anything _except_ a nested
> object: Assign source value
> 3. Target property exists, its value is a nested object, the source
> property value is anything _except_ a nested object: Assign source value
>
> The ambiguity:
>
> 4. Target property exists, its value is a nested object, the source
> property is a nested object: _____?
This seems to be close to the issue of copying an object. What is
exactly expected is as much ambiguous.

I would add to the ambiguity prototypal inheritance. All properties of
WebIDL objects are inherited getters. If you want to extend an object
with the values of a WebIDL object, do you loop through inherited
properties? (actually, if you don't, you have no property at all)
To the ambiguity, we can also add whether non-enumerable properties
should be assigned or not.
Facing function, do we want another function (callable with same body)
or juste the properties.
And finally, facing accessors, do we want to call the getter or copy it?
Bound to the original object it was extracted from or working with the
new object?

I'm of course not asking for answer, just enumerating other sources of
ambiguity

David


More information about the es-discuss mailing list