javascript - js對(duì)象 屬性的訪(fǎng)問(wèn)和創(chuàng)建
問(wèn)題描述
一個(gè)有意思的問(wèn)題:
var a = new Object(); var b = new Object(); var c = new Object(); c[a] = a; c[b] = b; console.log(c[a] === a); //輸出什么? ---> falseconsole.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); //輸出什么? ---> trueconsole.log(c.b === b); //輸出什么? ---> true
這里其實(shí)涉及到的就是[]運(yùn)算符 和.運(yùn)算符 相關(guān)知識(shí)。
附上相關(guān)規(guī)則和網(wǎng)址,你們自己研究吧:
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
問(wèn)題解答
回答1:其實(shí)就是個(gè) Object toString 的問(wèn)題。
相關(guān)文章:
1. mac里的docker如何命令行開(kāi)啟呢?2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?4. 關(guān)于docker下的nginx壓力測(cè)試5. docker容器呢SSH為什么連不通呢?6. nignx - docker內(nèi)nginx 80端口被占用7. 如何解決Centos下Docker服務(wù)啟動(dòng)無(wú)響應(yīng),且輸入docker命令無(wú)響應(yīng)?8. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????9. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。10. docker start -a dockername 老是卡住,什么情況?

網(wǎng)公網(wǎng)安備