简体   繁体   English

解构返回的未定义变量

[英]Destructuring returning undefined variables

I'm trying out the new destructuring feature of ES6, but having some trouble either understanding it, or getting it to work. 我正在尝试ES6的新解构功能,但是在理解它或使其工作时遇到了一些麻烦。

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. 我希望在控制台中看到"asd"function() { ... }但是两者都undefined

Using Firefox 28.0 使用Firefox 28.0

如果要分解对象,则必须使用该对象的结构:

var {testme, funcA} = test;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM