方括号前的 at 符号

At-sign before square brackets

我目前正在 Demandware 中维护一些 DS/JS 代码,我刚刚发现:

var XmlReponse : XML = new XML(result.object.text);
status = XmlReponse.@["STATUS"];

这个不寻常的“@[...]”语法有什么作用?

它可能与 ECMA-357 规范(又名 "E4X")有关,但我不确定:在 DW docs(需要凭据)中,据说:

"You can read values from an XML object the same way you would from standard ECMAScript objects"

var quantity = order.item(0).@quantity;
var singleItem = order.item.(@quantity == 1);

这似乎解释了 @ 但让我对以下方括号表示怀疑,也许是某种动态 属性 ?

谢谢:)

从阅读 manual 开始,它似乎阅读了 xml 元素的 属性。我看不出读取索引器会有什么不同

您提到的代码随后会读取 xml 响应

上的属性 STATUS

链接的ex4手册状态代码:

E4X allows you to access the attributes of a particular element with the .@ operator. The most basic case would look something like.

var element = <foo bar="1"/>
element.@bar = 2;