arrays - Dual variable assignment in JavaScript -
this question has answer here:
if have javascript function returns 2 values, possible assign values 2 variables in single statement?
for example, in python might like:
(var1, var2) = function()
i have tried few things tres this:
this.(var1, var2) = function();
i tried along lines of:
this.var1, this.var2 = function();
and
this.var1 = this.var2 = function();
i attempted using single array instead of multiple variables, complicate i'm trying accomplish later on because 2 variables used story x , y coordinates.
the answer yes can, works in browsers experimental technology, part of harmony (ecmascript 6) proposal, it's not recommended @ time of posting answer.
see destructuring assignment docs
function foo(){ return ["one", "two", "three"]; } var [one, two, three] = foo();
you can in 2 lines appreciate isn't want works.
var foo = foo(); var 1 = foo[0], 2 = foo[1], 3 = foo[2];
Comments
Post a Comment