An interesting question:
var a = new Object();
var b = new Object();
var c = new Object();
c[a] = a;
c[b] = b;
console.log(c[a] === a); //输出什么? ---> false
console.log(c[b] === b); //输出什么? ---> true
var a = new Object();
var b = new Object();
var c = new Object();
c.a=a;
c.b=b;
console.log(c.a === a); //输出什么? ---> true
console.log(c.b === b); //输出什么? ---> true
What is actually involved here is the knowledge related to the []
operator and the .
operator.
Attached are the relevant rules and URL, you can study it yourself:
MemberExpression : MemberExpression [ Expression ]
Let baseReference be the result of evaluating MemberExpression.
Let baseValue be GetValue(baseReference).
ReturnIfAbrupt(baseValue).
Let propertyNameReference be the result of evaluating Expression.
Let propertyNameValue be GetValue(propertyNameReference).
ReturnIfAbrupt(propertyNameValue).
Let bv be RequireObjectCoercible(baseValue).
ReturnIfAbrupt(bv).
Let propertyKey be ToPropertyKey(propertyNameValue).
ReturnIfAbrupt(propertyKey).
If the code matched by the syntactic production that is being evaluated is strict mode code, let strict be true, else let strict be false.
Return a value of type Reference whose base value is bv and whose referenced name is propertyKey, and whose strict reference flag is strict.
MemberExpression : MemberExpression . IdentifierName
Let baseReference be the result of evaluating MemberExpression.
Let baseValue be GetValue(baseReference).
ReturnIfAbrupt(baseValue).
Let bv be RequireObjectCoercible(baseValue).
ReturnIfAbrupt(bv).
Let propertyNameString be StringValue of IdentifierName
If the code matched by the syntactic production that is being evaluated is strict mode code, let strict be true, else let strict be false.
Return a value of type Reference whose base value is bv and whose referenced name is propertyNameString, and whose strict reference flag is strict.
CallExpression : CallExpression [ Expression ]
Is evaluated in exactly the same manner as MemberExpression : MemberExpression [ Expression ] except that the contained CallExpression is evaluated in step 1.
CallExpression : CallExpression . IdentifierName
Is evaluated in exactly the same manner as MemberExpression : MemberExpression . IdentifierName except that the contained CallExpression is evaluated in step 1.
ECMAScript 2015 #sec-property-accessors