ES6: var a,b,c; [a,b,c]=[1,2,3]; - destructuring assignments - Is that something coming soon? #1572
Replies: 5 comments
-
Posted at 2019-04-20 by @gfwilliams There's no plan for it right now, but it's definitely worth voting for on the ES6 wishlist. The issue is that as you mention "sometimes nothing is better than not all..." - while I'm sure most people would prefer to be able to use it in a simple way, if other features are anything to go by it's pretty much guaranteed I'll get "obscure feature X isn't working" bugs filed based on it, so if I implement it I'd have to be pretty clear about what was implemented. Also - to be sure I don't get your hopes up - this is another ES6 feature that's really unfriendly to implement in Espruino's parser, because you don't actually know whether |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-04-20 by @allObjects
I can vividly see that... because you try to resolve every '(sub)expression' as soon as possible. For the simplest solution - (plain) variable references - It would require to keep a prallel array with the references and when the PS: Did 'vote' on the ES6 wishlist. It is all very relative due to the nature of Espruino. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-04-23 by @gfwilliams Yes - I actually do something similar for arrow functions (eg. However that's not too bad because doing |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-09-20 by user134371 It's a new javascript construct in ES 6 that allows you to match property of an object in assignment. The syntax you need is: const { local: loc } = this.props which translates to: "declare a constant loc and assign it the value of property local from this.props". |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-09-21 by Robin Mon 2021.009.20
New is a bit misleading. . . . New back in 2015 While that (post #5) is a simple example @user134371, it is only a subset. A better reference:
A plethora of examples:
BTW @allObjects and @gfwilliams were discussing the intricacies and performance issues under the assumption there might be an inclusion in the future. I'm quite certain they've explored those complexities after pouring over the ECMAScript specification. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-04-19 by @allObjects
I know that there is always hunger for every thing to be in Espruino... ;-)
This multi-assignment / array and object destructuring assignment could give some space relieve for quite many things (the example though does not really portray that):
Would work for returns from functions as well:
I 'expect' only the simple implementation(s)... even though sometimes nothing is better than not all...
Beta Was this translation helpful? Give feedback.
All reactions