# Why was E4X deprecated??

**URL:** <https://es.discourse.group/t/why-was-e4x-deprecated/852>\
**Category:** I have questions\
**Created:** [July 13, 2021, 4:43pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852 "2021-07-13T16:43:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [July 13, 2021, 4:43pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/1 "2021-07-13T16:43:50Z")

</div>

I was just going through old MDN archives and found this; the E4X - ECMAScript for XML;  
The syntax:

```javascript
<script type="text/javascript;e4x=1">
var person = <person>
  <name> Bob Smith </name>
  <likes>
    <os> Linux </os>
    <browser> Firefox </browser>
    <language> JavaScript </language>
    <language> Python </language>
  </likes>
</person>;

alert(person.name); // Bob Smith
alert(person['name']); // Bob Smith
alert(person.likes.browser); // Firefox
alert(person['likes'].browser); // Firefox
</script>

```

Looks peculiar, dugh!! it's native JSX. I want to know why in the hell such a thing was depricated!😡😤

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [July 14, 2021, 2:58am UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/2 "2021-07-14T02:58:55Z")

</div>

No, it more closely aligns with JSON than JSX, if you read the implied semantics closely enough. Equivalent code would look closer to this:

```javascript
var person = {
  name: "Bob Smith",
  likes: {
    os: "Linux",
    browser: "Firefox",
    language: ["JavaScript", "Python"],
  },
};

alert(person.name); // Bob Smith
alert(person['name']); // Bob Smith
alert(person.likes.browser); // Firefox
alert(person['likes'].browser); // Firefox

```

Conversely, JSX is a language extension almost always remapped to something considerably more complicated.

**Edit:** I might be wrong on the `person.likes.language` bit, but I haven't actually used E4X. Also, of course, as you can see from my username, I'm very much not a TC39 member, and so I'm not really the authoritative source here.

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [July 14, 2021, 4:21am UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/3 "2021-07-14T04:21:53Z")

</div>

Sadly you're wrong about it because that example was taken from [MDN](https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X#working_with_xml_objects)  
It directly maps to an XML object; The syntax above is just a syntactic sugar for ` new XML("<person>...");` Just like JSX maps to a tree of Objects.  
It was designed as an alternative to the tedious and expensive XML DOM manipulation.  
The question still remains unanswered!!😢

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [July 14, 2021, 6:36am UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/4 "2021-07-14T06:36:17Z")

</div>

Just to reiterate:

> [@claudiameadows](#):
>
> **Edit:** I might be wrong on the `person.likes.language` bit, but I haven't actually used E4X.

I'm open to being wrong, and just throwing stuff at the wall. But IIUC it's the simpler nature of JSON that effectively destroyed E4X (it wasn't designed to work with the live DOM for one, sharply hampering its broader utility).

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)\
**Post date:** [July 14, 2021, 11:58am UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/5 "2021-07-14T11:58:19Z")

</div>

I would agree that it aligns more with the JSON example, not JSX. JSX usually maps to function calls, not structured data like JSON/E4X.

We supported E4X in ActionScript 3 (via Tamarin), but removed it in ActionScript 4, largely due to performance concerns. The extra parsing overhead wasn't worth the whatever benefit it may have provided, especially when there was a perfectly usable alternative going through the DOM API. Plus XML as a format was losing popularity largely due to JSON.

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [July 14, 2021, 12:34pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/6 "2021-07-14T12:34:08Z")

</div>

Guys this doesn't have anything to do with JSON; why bother to mention it here? It honestly feels  
to me like saying: "why use HTML when you can write it in JSON and convert it into DOM"; Nobody does that right; This question was all about ECMAScript for XML (E4X); i.e, the use of ECMAScript alongside the web standard XML. And the official word for dropping it. I just wanted to know what was wrong with it after it got implemented in SpiderMonkey why other browser vendors didn't endorse it.  
Please don't spam with invalid answers that lead the discussion astray from the main topic.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [July 17, 2021, 3:27pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/7 "2021-07-17T15:27:42Z")

</div>

JSX maps to function calls, but don't those function calls just produce a chunk of structured data? Sure, that piece of data is meant to be consumed by specific libraries, not userland code, but I would think React could have been implemented to use this E4X instead of JSX.

With that said, from the examples I've seen, I've never seen the ability to interpolate data into the XML structure (a big need for React programmers). There's also [this snippet of code](https://en.wikipedia.org/wiki/ECMAScript_for_XML) on wikipedia that's comes without any explanation, but from the looks of it, E4X is adding a whole bunch of other syntax features besides XML in Javascript.

```javascript
var sales = <sales vendor="John">
    <item type="peas" price="4" quantity="6"/>
    <item type="carrot" price="3" quantity="10"/>
    <item type="chips" price="5" quantity="3"/>
  </sales>;

alert( sales.item.(@type == "carrot").@quantity );
alert( sales.@vendor );
for each( var price in sales..@price ) {
  alert( price );
}
delete sales.item[0];
sales.item += <item type="oranges" price="4"/>;
sales.item.(@type == "oranges").@quantity = 4;

```

It looks like the "@" is used to refer to properties, and `.(@type == "oranges")` is some sort of query syntax to find a specific element. I'm not sure how this sales data is structured under the hood, but for all I know, these specific features turn E4X into a superset of Javascript that's incompatable with vanilla Javascript - i.e. maybe you can't refer to other Javascript libraries from this one, because of these underlying differences. If that's really the case, then that's a huge issue with this E4X thing.

I honestly have no idea, I'm just trying to speculate on different possible reasons why it didn't receive the same kind of popularity as JSX.

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [July 17, 2021, 4:24pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/8 "2021-07-17T16:24:46Z")

</div>

Thanks for the info!  
Trying to be a superset of JavaScript! I think that was a nail in the coffin for E4X. But it was introduced way back in 2004 when ECMAScript was very young. The new syntax was very alien(but revolutionary) to JavaScript; Like the for..each. Those funky syntaxes couldn't get through standardisation and eventually caused a huge gap between E4X & ECMAScript.  
But I think it's kind of cool actually ;)  
I also think that the XML standard later went with XSL, XQuery, XPath, XLink, XBase,..etc instead of creating an abomination of XML & JS.  
Any way these are just speculations and If anyone finds something else, please let me know.  
I really wish E4X to be reestablished.😢

---

<div class="post-metadata">

**Author:** ![claudepache](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudepache/32/236_2.png) [@claudepache](https://es.discourse.group/u/claudepache)\
**Post date:** [July 24, 2021, 7:38pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/9 "2021-07-24T19:38:43Z")

</div>

The following blog post from one of the JSX designers may interest you:

[https://blog.vjeux.com/2013/javascript/jsx-e4x-the-good-parts.html](https://blog.vjeux.com/2013/javascript/jsx-e4x-the-good-parts.html)

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [July 25, 2021, 4:45am UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/10 "2021-07-25T04:45:48Z")

</div>

Thank you very much! That explains a lot!

---

<div class="post-metadata">

**Author:** ![SpcFORK](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/spcfork/32/2134_2.png) [@SpcFORK](https://es.discourse.group/u/SpcFORK)\
**Post date:** [June 25, 2024, 2:35pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/11 "2024-06-25T14:35:36Z")

</div>

Because E4X is eh, when you could just do `XML()` in AS3, and `DOMParser().parseFromString(str, "text/xml");`  
Dynamic usage is better for data.

---

<div class="post-metadata">

**Author:** ![hydroperfox](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/hydroperfox/32/2233_2.png) [@hydroperfox](https://es.discourse.group/u/hydroperfox)\
**Post date:** [September 23, 2024, 7:14pm UTC](https://es.discourse.group/t/why-was-e4x-deprecated/852/12 "2024-09-23T19:14:12Z")

</div>

E4X also distinguishes property read versus method call.

```javascript
xn.length() // XML/XMLList "length" method
xn.length // "length" tags and processing-instructions

```
