Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.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 花括号内的变量初始化_Javascript_Reactjs_Commonjs - Fatal编程技术网

Javascript 花括号内的变量初始化

Javascript 花括号内的变量初始化,javascript,reactjs,commonjs,Javascript,Reactjs,Commonjs,这段代码翻译成什么?我无法理解大括号内的变量如何与=require('react-router')相关 它来自这是ES6中的一个功能。情况就是这样: // Imagine this is the object you require var reactRouter = { create: 'foo', HistoryLocation: 'bar', HashLocation: 'baz' } // Destructure var {create: createRouter, His

这段代码翻译成什么?我无法理解大括号内的变量如何与
=require('react-router')
相关

它来自

这是ES6中的一个功能。情况就是这样:

// Imagine this is the object you require
var reactRouter = {
  create: 'foo',
  HistoryLocation: 'bar',
  HashLocation: 'baz'
}

// Destructure
var {create: createRouter, HistoryLocation, HashLocation} = reactRouter

// Now the variables are in scope
console.log(createRouter, HistoryLocation, HashLocation)
//^ foo, bar, baz

看起来像是在分解作业。它是

destructuring assignment语法是一个JavaScript表达式,它可以使用反映数组和对象文本构造的语法从数组或对象中提取数据


酷的新功能!我很期待使用它。

解构作业。很好的解释。看起来很有趣!谢谢
// Imagine this is the object you require
var reactRouter = {
  create: 'foo',
  HistoryLocation: 'bar',
  HashLocation: 'baz'
}

// Destructure
var {create: createRouter, HistoryLocation, HashLocation} = reactRouter

// Now the variables are in scope
console.log(createRouter, HistoryLocation, HashLocation)
//^ foo, bar, baz