With ES6 and the various other upgrades to JavaScript, is there a way yet to dynamically declare variable names as (or) references to object properties, so that we do not have to constantly refer to the object.property syntax to access property values?

For example this syntax:

var obj = {a:1, b:2};  console.log(obj.a + " " + obj.b); // 1 2

or 

var obj = {a:1, b:2}, a = obj.a, b = obj.b; console.log(a + " " + b); // 1 2

Can it be converted to something like the following which can dynamically declare or reference each variable name based on the object's properties without having to declare them separately or so that each property reference doesn't have to specify the object name?

var (...obj); console.log(a + " " + b); // 1 2

The goal being that the console.log statement will work without having to reference the object or declare the variables individually?

I've read through the newer capabilities but am not finding anything to make this easier / shorter.

0

There are 0 best solutions below