I found compact function very useful (in php). Here is what it does:
$some_var = \'value\';
$ar = compact(\'some_var\');
//now $ar is array(\'so
If the variables are not in global scope it is still kinda possible but not practical.
function somefunc() {
var a = 'aaa',
b = 'bbb';
var compact = function() {
var obj = {};
for (var i = 0; i < arguments.length; i++) {
var key = arguments[i];
var value = eval(key);
obj[key] = value;
}
return obj;
}
console.log(compact('a', 'b')) // {a:'aaa',b:'bbb'}
}
The good news is ES6 has a new feature that will do just this.
var a=1,b=2;
console.log({a,b}) // {a:1,b:2}