1 回答
TA贡献1810条经验 获得超4个赞
你搞错了自增/自减符号的运算意义
它们的共同点是,把自身+1或者是-1之后的值赋值给自己,注意,是要把结果赋值给自己的。
那么你弄个常量来进行自增自减怎么可能不报错……
规范在这里,你可以参考一下:
UnaryExpression : ++ UnaryExpression
Let 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.
添加回答
举报