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.