Use of Colon in object assignment destructuring Javascript

南笙酒味 提交于 2019-12-05 01:11:05

问题


Working with React.js and React Router

import React, { Component } from 'react';

const PrivateRoute = ({ component: Component, ...rest }) => (
  <Route {...rest} render={} />
)

*{ component: Component, ...rest }*

..rest is the use of spread syntax but what does *component: Component* do


回答1:


In ES6 this will assign the value to a new variable in this case named foo

let obj = {
  name: 'Some Name',
  age: '42',
  gender: 'coder'
};
let { name: foo, ...rest } = obj;
console.log({foo, rest}) // { foo: 'Some Name', rest: { age: 42, gender: 'coder' } }
//

In this case, name will not be defined

for more go to this link



来源:https://stackoverflow.com/questions/51959013/use-of-colon-in-object-assignment-destructuring-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!