You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Konstantin Smirnov (Jira)" <ji...@apache.org> on 2022/10/07 09:22:00 UTC

[jira] [Updated] (GROOVY-10788) Consider adding Object deconstruction a-la Javascript

     [ https://issues.apache.org/jira/browse/GROOVY-10788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Konstantin Smirnov updated GROOVY-10788:
----------------------------------------
    Summary: Consider adding Object deconstruction a-la Javascript  (was: Object deconstruction a-la Javascript)

> Consider adding Object deconstruction a-la Javascript
> -----------------------------------------------------
>
>                 Key: GROOVY-10788
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10788
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Konstantin Smirnov
>            Priority: Major
>
> In JS you can perform following operations on Arrays:
> {code:java}
> const [ a, b, c ] = [ 1, 2, 3 ]
> {code}
> which corresponds to mutli-assignment in Groovy.
> However JS does some really nice syntactic sugar with Object deconstruction on top:
> {code:java}
> // "forward"
> const object = { question:'about life', answer:42, z:11 }
> const { question, answer } = object
> // "backward"
> const newObject = { question, answer }
> {code}
> This way you can save a lot of code-duplication between declaring variables and Map keys.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)