賦值運算符

2018-06-16 15:20 更新

語法

AssignmentExpression : ConditionalExpression LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpressionAssignmentExpressionNoIn : ConditionalExpressionNoIn LeftHandSideExpression = AssignmentExpressionNoIn LeftHandSideExpression AssignmentOperator AssignmentExpressionNoIn AssignmentOperator : one of *= /= %= += -= <<= >>= >>>= &= ^= |=

 語義

 AssignmentExpressionNoIn 執(zhí)行完全按照AssignmentExpression相同的方式,除了ConditionalExpressionNoIn替代了ConditionalExpression。

簡單賦值

 產(chǎn)生式 AssignmentExpression : LeftHandSideExpression = AssignmentExpression 按照下面的過程執(zhí)行 :

  1. 令 lref 為解釋執(zhí)行 LeftH 和 SideExpression 的結(jié)果 .
  2. 令 rref 為解釋執(zhí)行 AssignmentExpression 的結(jié)果 .
  3. 令 rval 為 GetValue(rref).
  4. 拋出一個 SyntaxError 異常,當(dāng)以下條件都成立 :Type(lref) 為 ReferenceIsStrictReference(lref) 為 trueType(GetBase(lref)) 為環(huán)境記錄項GetReferencedName(lref) 為 "eval" 或 "arguments"
  5. 調(diào)用 PutValue(lref, rval).
  6. 返回 rval.

 當(dāng)賦值發(fā)生在嚴(yán)格模式中時其LeftHandSide執(zhí)行結(jié)果不能是無法解引用的引用類型。假如這樣它會在賦值時拋出ReferenceError異常。 LeftHandSide也不能是到具有{[[Writable]]:false}特性的數(shù)據(jù)屬性的引用,到具有{[[Set]]:undefined}特性的訪問器屬性的引用,或者 [[Extensible]]內(nèi)部屬性值為false的對象上不存在的屬性。這些情況都會拋出TypeError異常。

組合賦值

 產(chǎn)生式 AssignmentExpression : LeftHandSideExpression'@ = AssignmentExpression, where @ represents one of the operators indicated above, 按照下面的過程執(zhí)行 :

  1. 令 lref 為解釋執(zhí)行 LeftH 和 SideExpression 的結(jié)果 .
  2. 令 lval 為 GetValue(lref).
  3. 令 rref 為解釋執(zhí)行 AssignmentExpression 的結(jié)果 .
  4. 令 rval 為 GetValue(rref).
  5. 令 r 為作用運算符 @ 于 lval 和 rval 的結(jié)果。
  6. 拋出一個 SyntaxError 異常,當(dāng)以下條件全部成立:Type(lref) 為 ReferenceIsStrictReference(lref) 為 trueType(GetBase(lref)) 為環(huán)境記錄項GetReferencedName(lref) 為 "eval" 或 "arguments"
  7. 調(diào)用 PutValue(lref, r).
  8. 返回 r.

 見 注11.13.1。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號