我正在尝试 ES6 的新解构特性,但在理解它或让它工作方面遇到了一些困难。
var test = {
testme: "asd",
funcA: function() {
console.log("A");
}
};
var [ testme, funcA ] = test;
console.log(testme);
console.log(funcA);
我希望在控制台中看到 "asd"
和 function() { ... }
但我得到的都是 undefined
。
使用 Firefox 28.0
最佳答案
如果你解构一个对象你必须使用对象的结构:
var {testme, funcA} = test;
关于javascript - 解构返回 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22563617/