Use of Colon in object assignment destructuring Javascript

前端 未结 1 765
我在风中等你
我在风中等你 2021-02-15 13:11

Working with React.js and React Router

import React, { Component } from \'react\';

const PrivateRoute = ({ component: Component, ...rest }) => (
  

        
1条回答
  •  遇见更好的自我
    2021-02-15 13:42

    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

    0 讨论(0)
提交回复
热议问题