Skip to content

Real-live example in LiveScript #4

@pepkin88

Description

@pepkin88

The feature from this proposal is implemented in LiveScript. You could use it as a playground and/or inspiration on how to handle the edge cases.

Note that the LiveScript implementation of this feature is a little bit different, than the proposed one.
In your example obj.{p1: new_p1, p2: {p21}, p3 = 3}, new_p1 is the property name in the newly created object. But in the LS implementation it would be p1.

I believe this could be the reasoning behind such order in the LS implementation:

obj2 = obj.{new_p1: p1, p2}
# being equivalent to
{p1, p2} = obj
obj2 = {new_p1: p1, p2}
# or
obj2 = {new_p1: obj.p1, obj.p2}
# in each case `new_p1` is on the left side of the colon

When setting multiple properties on an object, the order is consistent with object destructuring (which work similar as in JS). In the LS docs this operation is called substructuring:

dest.{a: c, b} = src
# equivalent to
{a: c, b} = src
dest.{c, b} = {c, b}
# which is equivalent to
dest.c = src.a
dest.b = src.b

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions