ESCMAScript 6箭头功能-参数周围的括号 [英] ESCMAScript 6 arrow functions - parentheses around parameter

查看:97
本文介绍了ESCMAScript 6箭头功能-参数周围的括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是javascript的新手,无法理解简单的东西-之间有什么区别

I'm new to javascript and cannot understand simple thing - what is the difference between

...(x) => { return x*2}

...x => { return x*2} //(just for example, may not work)

有人可以解释或提供描述链接吗?

Can someone explain or give link for description?

推荐答案

仅当有两个或更多输入参数时,才需要在输入参数(在本例中为x)周围加上括号.只有一个(如您在此处所示),这两个语句是相同的.

The parenthesis around input arguments (x in this case) are only required when there are two or more input arguments. With just one (as you've shown here), the two statements are identical.

(x) => { return x * 2; }x => { return x * 2; }

但是

(x, y) => { return x * y; }

在输入参数周围需要括号.

Requires parenthesis around the input arguments.

请参见 了解所有血腥细节!

See this for all the gory details!

这篇关于ESCMAScript 6箭头功能-参数周围的括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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