简体   繁体   中英

Use of Colon in object assignment destructuring Javascript

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

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

See assigning to new variable names

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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