在es6中,函数参数列表内的花括号有什么作用? [英] What do curly braces inside of function parameter lists do in es6?

查看:338
本文介绍了在es6中,函数参数列表内的花括号有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在使用的代码库中,我不断看到类似以下的函数:

I keep seeing functions that look like this in a codebase I'm working on:

const func = ({ param1, param2 }) => {
  //do stuff
}

这到底在做什么?我很难在Google上找到它,因为我什至不知道这叫什么或如何在Google搜索中对其进行描述.

What exactly is this doing? I'm having a hard time finding it on google, because I'm not even sure what this is called, or how to describe it in a google search.

推荐答案

它是

It is destructuring, but contained within the parameters. The equivalent without the destructuring would be:

const func = o => {
    var param1 = o.param1;
    var param2 = o.param2;
    //do stuff
}

这篇关于在es6中,函数参数列表内的花括号有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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