gpt4 book ai didi

javascript - x.y 和 x ['y' ] 是否会导致主机对象的不同行为?

转载 作者:行者123 更新时间:2023-11-29 21:55:10 24 4
gpt4 key购买 nike

对于普通(“ native ”)JavaScript 对象,其中属性名称是有效标识符,表达式 x.yx["y"] 始终在语义上等价。

Host Objects 是否保证这种等效性? ?

[..an] object supplied by the host environment to complete the execution environment of ECMAScript.

如果不是,是否有明显的异常(exception)? (在 Cocoon、Crosswalk、IE 等中?)

我尤其对 Window (window) 和其他 DOM 对象感兴趣;以及是否存在预期行为的任何已知“异常”,或者是否存在任何可能出现这种情况的环境。

最佳答案

应该是一样的。来自 Ecma-262 Edition 5.1 的第 11.2.1 节(属性访问器) ,我们有:

Properties are accessed by name, using either the dot notation:

MemberExpression . IdentifierName 
CallExpression . IdentifierName

or the bracket notation:

MemberExpression [ Expression ]
CallExpression [ Expression ]

The dot notation is explained by the following syntactic conversion:

MemberExpression . IdentifierName

is identical in its behaviour to

MemberExpression [ <identifier-name-string> ]

and similarly

CallExpression . IdentifierName

is identical in its behaviour to

CallExpression [ <identifier-name-string> ]

关于javascript - x.y 和 x ['y' ] 是否会导致主机对象的不同行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26834803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com