On object extension

David Bruant bruant.d at gmail.com
Mon Nov 28 13:02:42 PST 2011


Le 28/11/2011 21:00, Jake Verbaten a écrit :
> > First, if obj already has a non-configurable property 'a', this will
> throw 
>
> I don't think object extension on a non configurable properties should
> be a no op.
It was just an example. I explained later that the setting should happen
only when the existing property is either configurable or writable and
that if a property exists and the value is overridden, its attributes
should be kept constant.
Current proposal would turn a configurable non-writable property into a
writable property which is not a silent error, but rather a big mistake.

> Your basically saying "extend obj with { a: 1 } unless doing so would
> throw an error, in which case fail silently"
>
> Personally I don't like silent failure points.
I don't see it as a failure. I want to avoid to throw an error when the
property is non-writable and non-configurable. The problem with a
syntax-based operator is that it is written once for all.
-----
function addABC(obj){
  obj.{a:1, b:2, c:3};
}
-----
Should this function throw whenever the extension is not possible (a
property is non-writable & non-configurable) as written or do its best
to extend the object.
The problem with the former is that to ensure that the assignment won't
fail, one need to check that for all properties, there is no such
existing properties that is non-configurable and non-writable (which is
what i propose to do implicitly).

David


More information about the es-discuss mailing list