views:

187

answers:

3

Hi,

is there a javascript equivalent to unpack sequences like in python (a,b=(1,2))?

Thanks in advance.

A: 

There isn't. JavaScript doesn't have such syntax sugar.

Marcin
+2  A: 
[a, b] = [1, 2]
Antony Hatchkins
Which won't work in most javascript implementations...
Andy E
why? which implementations are affected? do you have further links?
Till Backhaus
Does not (seem to) work in IE6.
Alsciende
In opera 10 works, in ff 3 works, in ie 8 doesn't, in chrome doesn't. Not universal indeed.
Antony Hatchkins
Well, for starters this code won't work in IE, Chrome or Safari implementations. I'm pretty sure major browser-wise this is only supported by Firefox and Opera.
Andy E
@Alsciende I'm tempted to flag you comment as offensive for mentioning IE6 ;)
Till Backhaus
A: 

An object cannot contain a reference to an integer, only its value. So I can't see any way to do what you ask in javascript.

Alsciende