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.
添加回答
舉報