Javascript语法[]()和()() [英] Javascript syntax []() and ()()

查看:134
本文介绍了Javascript语法[]()和()()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解这些JavaScript语法。在下面的代码块中,在第二行。方括号后面是一个圆括号或括号,我怀疑是用来得到论据。我不明白这两个是如何被链接形成一个表达方式,它是什么意思。

I'm having trouble understanding these javascript syntaxes. In the block of code below, on the second line. The square bracket is quickly followed by a round bracket or parentheses which I suspected is used to get arguments. I do not understand how this two is being chained to form an expression and what it means.

 export const recipeCount = createReducer(0, {
      [types.ADD_RECIPE](state, action){
        return state + 1;
      }
    });

同样在这一行上,connect方法有两个参数,(state )=> {return {}} mapDispatchToProps 。然后用()和参数快速地回覆。起初,我虽然是java中的一些对象转换,但是没有意义。

Also on this line, the connect method takes in two arguments, (state) => {return {}} and mapDispatchToProps . Then it is quickly follwed by () with an argument. At first, i though it was some of object casting in java but that doesn't make sense.

export default connect((state) => {return {}}, mapDispatchToProps)(AppContainer);

代码执行正常并产生预期结果。我只是不明白发生了什么。请帮助,很高兴得到答案,伴随着我可以阅读的页面的链接,以便更好地了解。谢谢。

The code executes fine and produces expected result. I just don't understand what is going on. Pls Help, would be glad to get answersre accompanied with links to pages i can read for better understanding. Thanks.

推荐答案

答案在评论的问题。不得不再次将它们复制出来,所以我可以将问题标记为已回答并关闭它。

Answers are in the comment to the question. Had to copy them out again, so i can mark the question as answered and close it.

不知道第一个发生了什么,第二个, connect()是一个返回函数的函数,所以second()是立即调用返回的函数。 - Ouroborus

"Not sure what's going on with the first one. For the second one, connect() is a function that returns a function so the second () is to immediately call that returned function." – Ouroborus

第一个是一个动态对象文字属性,也是一个对象方法,我发现这是不可读的,我会重写一个。 - Davin Tryon

"The first one is a dynamic object literal property that is also an object method. I find this not readable at all. I would re-write that one. – Davin Tryon"

以及计算的属性名称以使其更清楚 - DenysSéguret

and also a link to Computed property names to make it clearer from – Denys Séguret

感谢贵司。

这篇关于Javascript语法[]()和()()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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