国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

javascript - js對象 屬性的訪問和創建

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

問題描述

一個有意思的問題:

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

這里其實涉及到的就是[]運算符 和.運算符 相關知識。

附上相關規則和網址,你們自己研究吧:

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

問題解答

回答1:

其實就是個 Object toString 的問題。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 宝山区| 新津县| 波密县| 福鼎市| 绿春县| 平定县| 太原市| 玉树县| 靖远县| 哈尔滨市| 东宁县| 麦盖提县| 文山县| 那曲县| 平和县| 乐东| 丹东市| 利辛县| 桃园县| 齐齐哈尔市| 遂川县| 西峡县| 彰化县| 遂宁市| 大姚县| 仪陇县| 定南县| 平潭县| 西和县| 瑞丽市| 上饶市| 盐源县| 瑞安市| 儋州市| 洛宁县| 沅江市| 简阳市| 綦江县| 青铜峡市| 东乡族自治县| 青浦区|