When returning an object from an arrow function, it seems that it is necessary to use an extra set of {}
and a return
keyword because of an ambiguity in the grammar.(从箭头函数返回对象时,由于语法上的歧义,似乎有必要使用额外的{}
和return
关键字。)
That means I can't write p => {foo: "bar"}
, but have to write p => { return {foo: "bar"}; }
(这意味着我不能写p => {foo: "bar"}
,而必须写p => { return {foo: "bar"}; }
) p => { return {foo: "bar"}; }
.(p => { return {foo: "bar"}; }
。)
If the arrow function returns anything other than an object, the {}
and return
are unnecessary, eg: p => "foo"
.(如果arrow函数返回的不是对象,则{}
和return
都是不必要的,例如: p => "foo"
。)
p => {foo: "bar"}
returns undefined
.(p => {foo: "bar"}
返回undefined
。)
A modified p => {"foo": "bar"}
throws “ SyntaxError
: unexpected token: ' :
'” .(修改后的p => {"foo": "bar"}
抛出“ SyntaxError
:意外令牌:' :
'” 。)
Is there something obvious I am missing?(有什么明显的我想念的东西吗?)
ask by jkschneider translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…