我不了解此语法javascript发生了什么 [英] I don't understand what's going on this syntax javascript

查看:69
本文介绍了我不了解此语法javascript发生了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在下面的代码中分配const { Types, Creators },我的意思是类型将要保留的内容以及创作者将要保留的内容.

How gonna assign in const { Types, Creators } in the below code I mean what Types gonna hold and what Creators gonna hold.

   const { Types, Creators } = createActions({
        userRequest: ['username'],
        userSuccess: ['avatar'],
        userFailure: null
    })



var createActions = (function (config, options) {
  if (R.isNil(config)) {
    throw new Error('an object is required to setup types and creators');
  }
  if (R.isEmpty(config)) {
    throw new Error('empty objects are not supported');
  }

  return {
    Types: convertToTypes(config, options),
    Creators: convertToCreators(config, options)
  };
})

推荐答案

语法是对象分解分配. TypesCreators将被定义为从createActions()调用返回的对象返回的TypesCreators属性.例如

The syntax is object destructuring assignment. Types and Creators will be defined as the Types and Creators properties returned from the object returned at createActions() call. For example

const {Types, Creators} = (() => {
  return {Types:0, Creators:1}
})();

console.log(Types, Creators)

这篇关于我不了解此语法javascript发生了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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