Re: [Python-ideas] Javascript Destructuring Assignment

Brett Cannon wrote:
I read it differently. I'm think you need to have a comma for each skipped element: [a,,,b] = [1,2,3,4,5] Anyone with in-depth knowledge, or FireFox 2.0 available to test this? Tim Delaney

On 3/6/07, Delaney, Timothy (Tim) <tdelaney@avaya.com> wrote:
Firefox 2.0 gives me these results: [a,,b] = [1,2,3,4]; a == 1 b == 3 [a,,,b] = [1,2,3,4]; a == 1 b == 4 [,a,,b] = [1,2,3,4]; a == 2 b == 4 /Tobias Ivarsson Tim Delaney

(re-sending, because I forgot to subscribe first...) Delaney, Timothy (Tim) wrote:
Oddly enough, I build a Javascript 1.7 interpreter just yesterday... js> [a,b] = [1,2] 1,2 js> a 1 js> b 2 js> [a,b] = [1,2,3] 1,2,3 js> a 1 js> b 2 js> [a,,b] = [1,2,3,4,5] 1,2,3,4,5 js> a 1 js> b 3 js> [a,,,b] = [1,2,3,4,5] 1,2,3,4,5 js> a 1 js> b 4 which is pretty much what I'ld expect. Having said that, it does make it easy to mess up in exactly the way you messed up in your example... Also, for the curious: js> [a,[b,c],d] = [1,2,3,4] 1,2,3,4 js> a 1 js> b js> c js> d 3 I'ld far prefer it to throw an error if you tried to unpack into a sequence of the wrong length, but that's not the Javascript way, I suppose... Later, Blake.

On 3/6/07, Delaney, Timothy (Tim) <tdelaney@avaya.com> wrote:
Firefox 2.0 gives me these results: [a,,b] = [1,2,3,4]; a == 1 b == 3 [a,,,b] = [1,2,3,4]; a == 1 b == 4 [,a,,b] = [1,2,3,4]; a == 2 b == 4 /Tobias Ivarsson Tim Delaney

(re-sending, because I forgot to subscribe first...) Delaney, Timothy (Tim) wrote:
Oddly enough, I build a Javascript 1.7 interpreter just yesterday... js> [a,b] = [1,2] 1,2 js> a 1 js> b 2 js> [a,b] = [1,2,3] 1,2,3 js> a 1 js> b 2 js> [a,,b] = [1,2,3,4,5] 1,2,3,4,5 js> a 1 js> b 3 js> [a,,,b] = [1,2,3,4,5] 1,2,3,4,5 js> a 1 js> b 4 which is pretty much what I'ld expect. Having said that, it does make it easy to mess up in exactly the way you messed up in your example... Also, for the curious: js> [a,[b,c],d] = [1,2,3,4] 1,2,3,4 js> a 1 js> b js> c js> d 3 I'ld far prefer it to throw an error if you tried to unpack into a sequence of the wrong length, but that's not the Javascript way, I suppose... Later, Blake.
participants (3)
-
Blake Winton
-
Delaney, Timothy (Tim)
-
Tobias Ivarsson