archives

« Bugzilla Issues Index

#356 — AssignmentPattern does not allow initializers


The following does not seem allowed with the grammar for ObjectAssignmentPattern:

var x;
{y: x = 1} = {z: 2}
assert(x === 1);

Similar issues are there for ArrayAssignmentPattern.

Is this intentional?


(In reply to comment #0)
>
> Is this intentional?

It is. I think there was some es-discuss talk that led to that conclusion. However, looking at it now I don't see any compelling reason to not have them.

Related is the more general question of what should happen when the property doesn't exist in the source object. As currently specified undefine is used as the source value for the LHSExpression. A reasonable alternative would be to skip that LHS entirely. EG:

var a=1,b=2;
{a,b} ={ a:3};

console.log(a,b); //current spec: 3, undefined
//reasonable alternative: 3, 2

Which makes more sense?


fixed in "Rev 8", June 12,2012 draft