Is .@ a Javascript symbol?
Asked Answered
L

1

5

I find the following code in some file:

var node = <title />;
node.@name = "titleName";

The node is

<title>
 <name>titleName<name/>
</title>

So What's the .@ operator meaning?

Lx answered 17/2, 2014 at 6:17 Comment(7)
That's not valid JavaScript.Brockway
While are we at it @meagar, do we know which language would such symbol belong to?Sousaphone
@Sousaphone My best guess would be, a template file.Rectilinear
And then, there's all of those languages that compile to JavaScript. My guess was going to be TypeScript or something, but then I saw var node = <title />;, and I can't imagine that would be valid in anything.Shepard
I think we should upvote. This is a valid question. But kudos to pswg helping figuring out. We shouldn't be harsh on "strange" question like this.Sousaphone
@Sousaphone But then how can pswg earn the reversal badge?Smoothshaven
Maybe he has it already, considering the amount of gold badges he has.Bil
A
9

This looks like ECMAScript for XML (E4X), an extension for ECMAScript (on which JavaScript is based). It was standardized in ECMA-357, but it was not widely adopted by the major browser vendors, and was dropped from later ECMAScript standards. However, it is still supported by some engines, including ActionScript 3.0.

It's used for working with XML more gracefully. The .@ syntax references an XML attribute within an XmlNode, and in this case, node.@name = "titleName" sets the attribute name on node to the value "titleName".

Aliquot answered 17/2, 2014 at 6:26 Comment(1)
I'm using AS3.0 actually :-)Lx

© 2022 - 2024 — McMap. All rights reserved.