Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.JS中的解构_Javascript_Node.js_Ecmascript 6_Destructuring - Fatal编程技术网

Javascript Node.JS中的解构

Javascript Node.JS中的解构,javascript,node.js,ecmascript-6,destructuring,Javascript,Node.js,Ecmascript 6,Destructuring,声称EMCAScript 6解构已在Node.JS中部分实现。我尝试了各种示例(使用v0.10.12和--harmony标志),例如 及 无济于事。似乎表明V8中还不支持解构 Node.JS中是否真正部分实现了分解结构?我可以使用哪些代码片段?针对node v6和更新版本的更新:node v6支持无需任何特殊需要的解构分配: var [a, b] = [1, 2]; 对于较旧版本的node:您可以通过键入以下内容获取支持的和声功能列表: node--v8选项| grep harmony 节点5

声称EMCAScript 6解构已在Node.JS中部分实现。我尝试了各种示例(使用v0.10.12和
--harmony
标志),例如

无济于事。似乎表明V8中还不支持解构


Node.JS中是否真正部分实现了分解结构?我可以使用哪些代码片段?

针对node v6和更新版本的更新:node v6支持无需任何特殊需要的解构分配:

var [a, b] = [1, 2];
对于较旧版本的node:您可以通过键入以下内容获取支持的和声功能列表:

node--v8选项| grep harmony

节点5.x将为您提供:

--es_staging (enable all completed harmony features)
--harmony (enable all completed harmony features)
--harmony_shipping (enable all shipped harmony fetaures)
--harmony_modules (enable "harmony modules" (in progress))
--harmony_regexps (enable "harmony regular expression extensions" (in progress))
--harmony_proxies (enable "harmony proxies" (in progress))
--harmony_sloppy_function (enable "harmony sloppy function block scoping" (in progress))
--harmony_sloppy_let (enable "harmony let in sloppy mode" (in progress))
--harmony_unicode_regexps (enable "harmony unicode regexps" (in progress))
--harmony_reflect (enable "harmony Reflect API" (in progress))
--harmony_destructuring (enable "harmony destructuring" (in progress))
--harmony_default_parameters (enable "harmony default parameters" (in progress))
--harmony_sharedarraybuffer (enable "harmony sharedarraybuffer" (in progress))
--harmony_atomics (enable "harmony atomics" (in progress))
--harmony_simd (enable "harmony simd" (in progress))
--harmony_array_includes (enable "harmony Array.prototype.includes")
--harmony_tostring (enable "harmony toString")
--harmony_concat_spreadable (enable "harmony isConcatSpreadable")
--harmony_rest_parameters (enable "harmony rest parameters")
--harmony_sloppy (enable "harmony features in sloppy mode")
--harmony_arrow_functions (enable "harmony arrow functions")
--harmony_new_target (enable "harmony new.target")
--harmony_object_observe (enable "harmony Object.observe")
--harmony_spreadcalls (enable "harmony spread-calls")
--harmony_spread_arrays (enable "harmony spread in array literals")
--harmony_object (enable "harmony Object methods")
节点4.1中添加了您需要的标志--harmony\u destructuring。当前,您需要传递
--harmony\u destructuring
标志以启用该功能:

$ node --harmony_destructuring
> var {foo} = {foo: 'bar'};
undefined
> foo
'bar'

显示Chrome 45或Node v4都不支持分解结构。

最新发布的Node.js v6使用的是V8版本5.0,它是ES2015语言功能的93%(甚至是v6.1中的96%)


解构分配现在可以被认为是稳定的,并且可以在没有任何标志的情况下使用。

即使在节点v5.0.0中使用
节点--harmony\u解构
它也可以使用
节点--harmony\u解构
。我不知道v4.2在Node4.2.2中对我有用--现在支持最新的Chrome(49)解构的harmony_解构。只要您坚持使用Chrome或Node(带有适当的标志),您现在就可以使用几乎所有的ES6,而不需要像Babel这样的transpiler。@BrianMcCutchon不带
var
,您需要执行
({foo}={foo:'bar})
来防止出现前导
{
被解释为启动一个块。这在任何实现中都是一样的。@torazaburo很有趣,没有想到这一点。在分解数组时,您应该能够省略
var
/
let
,但在节点中似乎还不起作用。
--es_staging (enable all completed harmony features)
--harmony (enable all completed harmony features)
--harmony_shipping (enable all shipped harmony fetaures)
--harmony_modules (enable "harmony modules" (in progress))
--harmony_regexps (enable "harmony regular expression extensions" (in progress))
--harmony_proxies (enable "harmony proxies" (in progress))
--harmony_sloppy_function (enable "harmony sloppy function block scoping" (in progress))
--harmony_sloppy_let (enable "harmony let in sloppy mode" (in progress))
--harmony_unicode_regexps (enable "harmony unicode regexps" (in progress))
--harmony_reflect (enable "harmony Reflect API" (in progress))
--harmony_destructuring (enable "harmony destructuring" (in progress))
--harmony_default_parameters (enable "harmony default parameters" (in progress))
--harmony_sharedarraybuffer (enable "harmony sharedarraybuffer" (in progress))
--harmony_atomics (enable "harmony atomics" (in progress))
--harmony_simd (enable "harmony simd" (in progress))
--harmony_array_includes (enable "harmony Array.prototype.includes")
--harmony_tostring (enable "harmony toString")
--harmony_concat_spreadable (enable "harmony isConcatSpreadable")
--harmony_rest_parameters (enable "harmony rest parameters")
--harmony_sloppy (enable "harmony features in sloppy mode")
--harmony_arrow_functions (enable "harmony arrow functions")
--harmony_new_target (enable "harmony new.target")
--harmony_object_observe (enable "harmony Object.observe")
--harmony_spreadcalls (enable "harmony spread-calls")
--harmony_spread_arrays (enable "harmony spread in array literals")
--harmony_object (enable "harmony Object methods")
$ node --harmony_destructuring
> var {foo} = {foo: 'bar'};
undefined
> foo
'bar'