Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Should we include “optional property assignment” a?.b = c #18

@claudepache

Description

@claudepache

For the most general case illustrating short-circuiting, the instruction:

a?.b.c().d = e;

is equivalent to:

if (a != null)
    a.b.c().d = e;

@alangpierce has found real-world usages of that form in CoffeeScript, some of them seem reasonable, including two-level deep chains a?.b.c = d:
https://gist.github.com/alangpierce/34b7aa40cda51b0a089a44680bdfed7e

Should we include that? In particular, are the semantics clear enough? There are the following subcases:

  • simple assignment: a?.b = c
  • combined assignment: a?.b += c, a?.b >>= c, etc.
  • increment/decrement: a?.b++, --a?.b, etc.
  • destructuring assignment: { x: a?.b } = c, [ a?.b ] = c, etc.
  • for-in/of loop header: for (a?.b in c), for (a?.b of c)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions