Question

I'm trying out the new destructuring feature of ES6, but having some trouble either understanding it, or getting it to work.

var test = {
    testme: "asd",
    funcA: function() {
       console.log("A");
   }
};
var [ testme, funcA ] = test;
console.log(testme);
console.log(funcA);

I expected to see in the console "asd" and function() { ... } but I get undefined for both.

Using Firefox 28.0

Was it helpful?

Solution

If you destructure an object you have to use the object's structure:

var {testme, funcA} = test;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top