Generalization of destructuring assignment, has this been discussed before?

Brendan Eich brendan at
Wed Sep 21 01:27:01 PDT 2011

On Sep 21, 2011, at 12:17 AM, Lasse Reichstein wrote:

> Destructuring allows, e.g.,
>   var o = {};
>   [o.x, o.y] = [1, 2];
> I.e., a generic LValue as a Field.
> Could this be generalized to working outside of array/object braces in declarations, e.g.:
>   var o.x = 42;   // Declared non-configurable
>   const o.x = 37;  // Declared non-Wrtiable and non-configurable

o must denote an object already, right? Just checking -- some might want o if unbound to magically be bound to a fresh object, which would be deeply wrong.

> and the *real* reason for suggesting it, a highly convenient shorthand:
>   function { ... }

This is an oldie, we talked about it in ES1 days, IIRC JScript supported (supports?) it.

> I think I have seen this suggested before, but it might just be Crockford's web pages at some point (perhaps the one suggesting "::" as abbreviation for ".prototype."). Has it been suggested for ES?

"::" is wanted for guards. extends CoffeeScript to use :: for guard-ish contracts while leaving Coffee's use of :: intact. Yes, significant whitespace.

> There doesn't seem to be any syntactic ambiguity (but it can foil look-ahead on functions if function 
> calls are allowed as LValues, since "function foo()()()()()()()() { ... } " won't know which parenthesis
> starts the arguments until it sees the end of them). 

I don't see how function foo()() is legal unless you are thinking of an extension such as ES4/JS1.8+ "expression closures" where the body can be an expression.

> Ofcourse, "classes" might remove the usecase for "in place function declaration" above.

Sure, but I've never understood why people want to write

Foo.prototype.m1 = function (...){...};
Foo.prototype.m2 = function (...){...};
Foo.prototype.m3 = function (...){...};

instead of

Foo.prototype = {
  m1: function (...){...},
  m2: function (...){...},
  m3: function (...){...},

The exact grammar for the dotted expression is unclear. Would you allow any member expression, even one with bracketed index expressions? Side effects? Where to draw the line?

In light of all this, I don't see a strong argument for allowing declarations to have dotted expressions instead of identifiers.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list