js 规范 -- 赋值
今天遇到一个小问题:
1 | let id: number = 0; |
当时我以为是:[undefined, 1],而实际是 [1]。
理解原理就是查看文档:
The production AssignmentExpression : LeftHandSideExpression = AssignmentExpression is evaluated as follows:
- Let lref be the result of evaluating LeftHandSideExpression.
- Let rref be the result of evaluating AssignmentExpression.
- Let rval be GetValue(rref).
- Throw a SyntaxError exception if the following conditions are all true:
- Type(lref) is Reference is true
- IsStrictReference(lref) is true
- Type(GetBase(lref)) is Environment Record
- GetReferencedName(lref) is either “eval” or “arguments”
- Call PutValue(lref, rval).
- Return rval.
其实不用看后面,前面就说了,先求左值,再求右值。。