JavaScript如何简写赋值方法
简写赋值方法
如果你正在使用任何流行的 Web 框架,那么你很有可能使用数组或以对象本文的形式将数据在组件和 API 之间进行通信。一旦数据对象到达一个组件,你就需要解压它。例如:
const observable = require('mobx/observable');const action = require('mobx/action');const runInAction = require('mobx/runInAction');const store = this.props.store;const form = this.props.form;const loading = this.props.loading;const errors = this.props.errors;const entity = this.props.entity;
可以简写为:
import { observable, action, runInAction } from 'mobx';const { store, form, loading, errors, entity } = this.props;
也可以分配变量名:
// 最后一个变量名为 contact
const { store, form, loading, errors, entity:contact } = this.props;
本文标题:JavaScript如何简写赋值方法
本文链接:https://www.qqooo.cn/post/7081.html
版权说明:网站文章均来源于手工整理和网友投稿,若有不妥之处请来信 xsds@vip.qq.com 处理,谢谢!