E4X Lives
So I finally got around to downloading Dear Park Alpha 2 to start playing. Naturally, I went right for the JavaScript changes. Yes, the Array extensions are nice, but I really wanted to check out the implementation of ECMAScript for XML (E4X). So I opened up my editor and typed a simple E4X example, loaded it up and…got a syntax error. After some digging around, I found that you need a specific content type on the <script/> tag in order to make it work. Simply doing <script> or <script type="text/javascript"> won’t work. Instead, you need to do this:
<script type="application/x-javascript; e4x=1">
I’m not sure how well this will go over. By doing this, Internet Explorer ignores the code altogether, which could be good or bad. On the one hand, it ensures that other browsers will (hopefully) ignore script that they don’t support. On the other hand, though, it disallows testing for E4X support by testing for the XML object.
These issues aside, I must say that I love E4X. I loved it when I read the initial spec and wrote about it in my book, and I love it even more now that I’m able to use it in a browser. This is the best thing to happen to the Web since the DOM.
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.
Both comments and pings are currently closed.




2 Comments
But the for in loop is an abomination and breaks the js semantics. They should have introduced a new foreach loop instead.
Erik Arvidsson on August 2nd, 2005 at 4:38 pm
Js is niice, except the use of + to concat strings. This new sintaxy sugar will attract more interesting coders, that will make interesting code.
Tei on September 14th, 2005 at 11:14 am
Comments are automatically closed after 14 days.