[Python-ideas] Javascript Destructuring Assignment

Brett Cannon brett at python.org
Tue Mar 6 00:12:58 CET 2007


On 3/5/07, Talin <talin at acm.org> wrote:
> As you probably know, the next version of Javascript (1.7) will have a
> number of ideas that have been borrowed from Python. In particular, the
> "tuple assignment" syntax will now be supported in Javascript, which
> will be a pleasant addition to the language.
>
> However, I noticed that the Javascript version is, in some respects, a
> superset of the Python functionality.
>
> If you are interested, you might have a look at this page:
>
>     http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7
>
> Go to the section called "Destructuring assignment" to check out how the
> new syntax is going to work.
>
> As an example of what I mean, the Javascript unpacking syntax will allow
> variables to be skipped:
>
>    [a,,b] = [1,2,3]
>
> In other words, a is assigned the value 1, the value 2 is thrown away,
> and b is assigned the value 3. In today's Python, this requires a dummy
> variable.

It skips in the middle?!?  Yuck.

>
> I admit that this is not a particularly important feature; However,
> given that Javascript is being inspired by Python in this case, maybe it
> would be appropriate to return the favor?
>

I personally am -1 on the idea.  Explicit is better than implicit.

-Brett



More information about the Python-ideas mailing list