久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

javascript - js對(duì)象 屬性的訪問(wèn)和創(chuàng)建

瀏覽:100日期:2023-02-28 14:42:50

問(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)題。

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 视频| 绩溪县| 成武县| 永善县| 梧州市| 潢川县| 巴南区| 通渭县| 青神县| 长葛市| 福安市| 沧州市| 洛浦县| 南平市| 莎车县| 长乐市| 广宁县| 定州市| 革吉县| 镇赉县| 景洪市| 木里| 福州市| 安乡县| 巧家县| 阿勒泰市| 石家庄市| 桐庐县| 浦东新区| 岳西县| 沽源县| 沁水县| 许昌县| 茌平县| 顺昌县| 龙胜| 凌云县| 卢湾区| 商南县| 新安县| 瓦房店市|