rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
160 stars 46 forks source link

Destructuring Assignment Support #5

Open chrisdp opened 5 years ago

chrisdp commented 5 years ago

Like we have in javascript, support for this would be very covenant.

TwitchBronBron commented 5 years ago

Can you provide an example in brighterscript syntax and then the complied brightscript?

chrisdp commented 5 years ago

BrighterScript Array

foo = ["one", "two", "three"]

([one, two, three] = foo)

print one 
' Output: one

print two 
' Output: two

print three 
' Output: three

BrightScript Array

foo = ["one", "two", "three"]

one = foo[0]
two = foo[1]
three = foo[2]

print one 
' Output: one

print two 
' Output: two

print three 
' Output: three

BrighterScript Object

o = {p: 42, q: true};
({p, q} = o)

print p 
' Output: 42

print q
' Output: true

BrightScript Object

o = {p: 42, q: true};
p = o.p
q = o.q

print p 
' Output: 42

print q
' Output: true

@TwitchBronBron There are many more but as this would be a good start. Here is the javascript doc I am looking at for reference. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment