From 081dd4f47b76538796fb0b903584d28a49c26d67 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Fri, 24 May 2019 17:45:22 +0300 Subject: [PATCH] Cascade Operator --- proposal-template.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/proposal-template.md b/proposal-template.md index c928a70..6faac82 100755 --- a/proposal-template.md +++ b/proposal-template.md @@ -1,16 +1,32 @@ -# ECMAScript proposal: @Name +# ECMAScript proposal: Cascade Operator - [Motivation](#motivation) - [High-level API](#high-level-api) - [FAQ](#faq) ## Motivation -Proposal motivation +If i want change some properties inside existed object it will be wieard: + +```js +const user = { name: "user", password: "password", likes: 0, friends: [...] }; + +const updatedUser = { + ...user, + friends: user.friends.concat(newFriend), + likes: user.likes + 1, +} +``` + +I propose Dart-like Cascade Operator which will be more declarative than previous object update ## High-level API ```js -// example code +const user = { name: "user", password: "password", likes: 0, friends: [...] }; + +const updatedUser = user + ..friends.concat(newUsser) + ..likes += 1; ``` ### FAQ