der*_*can 4 javascript commonjs reactjs
这段代码转化为什么?我无法弄清楚花括号内的变量是如何与之相关的= require('react-router').
var { create: createRouter, HistoryLocation, HashLocation } = require('react-router')
Run Code Online (Sandbox Code Playgroud)
它来自这个回购
这是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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2444 次 |
| 最近记录: |