简体   繁体   English

谁能指出我在ecma-262中定义使用括号作为回报的标准吗?

[英]Can anyone point me to the standards in ecma-262 that defines using parentheses for returns?

// Create a component named MessageComponent
var MessageComponent = React.createClass({
  render: function() {
    return (
      <div>{this.props.message}</div>
    );
  }
});

NOTE Why do we need the parentheses around the return statement (line 3)? 注意为什么我们需要在return语句(第3行)周围加上括号? This is because of JavaScript's automatic semicolon insertion. 这是因为JavaScript的自动分号插入。 Without the parentheses, JavaScript would ignore the following lines and return without a value. 如果没有括号,JavaScript将忽略以下各行并返回无值。 If the JSX starts on the same line as the return, then parentheses are not needed. 如果JSX与返回值在同一行开始,则不需要括号。

Taken from here . 取自这里

There is no specific part of the spec that handles using parens for returns. 规范中没有特定部分可以使用parens获取收益。 Parenthesis is just one way to create an expression. 括号只是创建表达式的一种方法。

When a continue, break, return, or throw token is encountered and a LineTerminator is encountered before the next token, a semicolon is automatically inserted after the continue, break, return, or throw token. 当遇到继续,中断,返回或抛出令牌并且在下一个令牌之前遇到LineTerminator时,将在继续,中断,返回或抛出令牌之后自动插入分号。

http://www.ecma-international.org/ecma-262/5.1/ http://www.ecma-international.org/ecma-262/5.1/

Looks like the parentheses here are just vanilla JS expressions wrapped in parentheses ie return (1 + 2), except multi-line: 看起来这里的括号只是用括号括起来的原始JS表达式,即return(1 + 2),多行除外:

function x() {
    return (
        1 + 2
    );
}

*Edited to not use the word closure. *编辑为不使用单词closure。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM