简体   繁体   English

Javascript运算符优先级技术性

[英]Javascript operator precedence technicality

I'm having a hard time understanding what is meant by the combination of Exponentiation and everything else (Multiplication, Division, etc) in group 14 of the Javascript precedence. 我很难理解在Javascript优先级的第14组中,Exponentiation和其他所有内容(乘法,除法等)的组合意味着什么。

Source - MDN 来源 - MDN

Three questions: 三个问题:

  1. What is the meaning of combining the right-to-left and left-to-right associativity in one group? 在一个组中组合从右到左和从左到右的关联性是什么意思?
  2. How can the expression 2 ** 3 * 4 be rephrased according to these rules, and still get the same answer? 如何根据这些规则对表达式2 ** 3 * 4进行改写,仍然得到相同的答案? 4 * 2 ** 3 works...is that what's meant? 4 * 2 ** 3作品......是什么意思?
  3. When / how is this not equivalent to the seemingly simpler expedient of giving exponentiation higher precedence? 何时/如何不等于看似更简单的赋予取幂优先权的权宜之计?

1) 2 ** 3 ** 4 , being right-to-left associative, is 2 ** (3 ** 4) . 1) 2 ** 3 ** 4 ,从右到左关联,是2 ** (3 ** 4) 2 / 3 / 4 , being left-to-right associative, is (2 / 3) / 4 . 2 / 3 / 4 ,从左到右关联,是(2 / 3) / 4

2/3) I believe 2 ** 3 * 4 is (2 ** 3) * 4 . 2/3)我相信2 ** 3 * 4(2 ** 3) * 4 2 * 3 ** 4 is 2 * (3 ** 4) (as evaluated by es6fiddle ). 2 * 3 ** 42 * (3 ** 4) (由es6fiddle评估)。

This does not follow from the table; 这不是从表中得出的; but exponentiation should have precedence over multiplication. 但取幂应优先于乘法。 Mixing left-to-right and right-to-left in one precedence rank is strange. 在一个优先级别中从左到右和从右到左混合是很奇怪的。 In fact, as far as I could see in ES7 drafts , it is not at all treated grammatically the same way as * , / and % , but as a unary operation (!). 事实上,就我在ES7草案中所看到的而言,它在语法上与*/% ,而是作为一元操作(!)。

Also note that no engines other than Babel and Traceur have support for ** at the current time, so it is mostly academic at this point. 另请注意,除了Babel和Traceur之外,目前没有任何引擎支持** ,所以此时它主要是学术性的。 MDN is a wiki, and exponentiation operator was added by a Mozillian; MDN是一个wiki,并且由Mozillian添加了取幂运算符; but AFAIK since Mozilla doesn't currently support ** , it does not actually document the way Mozilla interprets the language. 但是AFAIK,因为Mozilla目前不支持** ,它实际上并没有记录Mozilla解释语言的方式。

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

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