报错Uncaught ReferenceError: Invalid left-hand side expression in prefix operation
为什么只是一个是存入变量就不会报错 一个是直接暴露出来 就报错
慕田峪9158850
浏览 613回答 1
1回答
慕莱坞森
你搞错了自增/自减符号的运算意义它们的共同点是,把自身+1或者是-1之后的值赋值给自己,注意,是要把结果赋值给自己的。那么你弄个常量来进行自增自减怎么可能不报错……规范在这里,你可以参考一下:UnaryExpression : ++ UnaryExpressionLet expr be the result of evaluating UnaryExpression.Let oldValue be ToNumber(GetValue(expr)).ReturnIfAbrupt(oldValue).Let newValue be the result of adding the value 1 to oldValue, using the same rules as for the + operator (see 12.7.5).Let status be PutValue(expr, newValue).ReturnIfAbrupt(status).Return newValue.PostfixExpression : LeftHandSideExpression ++Let lhs be the result of evaluating LeftHandSideExpression.Let oldValue be ToNumber(GetValue(lhs)).ReturnIfAbrupt(oldValue).Let newValue be the result of adding the value 1 to oldValue, using the same rules as for the + operator (see 12.7.5).Let status be PutValue(lhs, newValue).ReturnIfAbrupt(status).Return oldValue.