在对象分配破坏Javascript中使用冒号 [英] Use of Colon in object assignment destructuring Javascript

查看:36
本文介绍了在对象分配破坏Javascript中使用冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用React.js和React Router

Working with React.js and React Router

import React, { Component } from 'react';

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

* {组件:组件,... rest} *

.. rest是传播语法的使用,但是 * component:Component * 的作用

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

推荐答案

在ES6中,这会将值分配给一个新变量,在本例中为 foo

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' } }
//

在这种情况下,将不会定义 name

In this case, name will not be defined

请参见分配给新的变量名称

这篇关于在对象分配破坏Javascript中使用冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆