nik*_*sfi 5 javascript safari syntax operator-precedence async-await
在JavaScript中,如何解释以下语句:
cond1 && !await f()
Run Code Online (Sandbox Code Playgroud)
这是该行的摘录
if(cond1 && !await f()){
do_stuff();
}
Run Code Online (Sandbox Code Playgroud)
在生产应用程序中.chrome似乎很好用,但在ios上这会导致读取错误
unexpected identifier 'f'. Expected ')' to end an if condition.
Run Code Online (Sandbox Code Playgroud)
看起来ios变成!await f()了(!await)(f())而不是!(await f()).
现在问我的问题:根据ECMA-262对上述线路的正确解释是什么?
ps:我们已经修改了ios的代码,将其更改为
var f_result = await f();
if(cond1 && !f_result){
do_stuff();
}
Run Code Online (Sandbox Code Playgroud)
这与运算符优先级无关。由于两者都是一元前缀运算符,因此该表达式只有一种解释方式 - 所有delete、void、typeof、+、-、~和!都await以相同的生产目标进行解析,并且可以任意嵌套。是的,它是 ES2017 中的有效语法。