October 12, 2007

E4X's double dot operator

ECMAScript 4 (currently implemented in ActionScript, but not directly in web browsers which are still dealing with ECMAScript 3 incompatibilities) has a couple of very neat power-features that will save some lines of code, especially when using the E4x extension (ECMAScript 4 XML).

One of them is the double dot (..) operator. As in
myElement..subNode

This is an array of all "subNode" children below myElement. For a Canvas, myCanvas..Label will be an array of all the Labels in your canvas. Neat, huh?

How about the .@ operator? As in...
myCanvas..Label.@(thisXML.@id == "1234").text

This will help you select directly the first Label with an attribute of id equal to 1234.

2 comments:

  1. It would be great if Internet Exploder would implement E4X. It's in Firefox. And flex. What is holding up ie???????

    ReplyDelete
  2. Well, we go down to the same dispute: IE vs Firefox, own-implementation vs standard, own-CSS vs standard-compliant-CSS, etc. After the technologies will prove themselves useful for developers and stable, IE will budge. I guess...

    ReplyDelete