If I have a function like this:
function doSomething(opt)
{
}
And I call it like this:
doSomething({a: 234, b: 567});
Is there a Javascript equivalent of the PHP extract() function so that I could do this:
function doSomething(opt)
{
extract(opt);
alert(a); // 234
alert(b); // 567
}
The with() statement is not recommended any more and using the 'this' variable accesses the global scope - not the functions scope.
UPDATE:
Currently I'm doing the extraction manually like this:
function doSomething (opt)
{
var a = opt.a,
b = opt.b;
}
function doSomething({a, b}){ a, b } = opt