E4X and Prototype Goodness

I got around to trying the E4X-based query structure this morning, and it works like a charm.  It's now possible to write your queries like this:

Query.execute(
  <query>
    update contact set
      name = :name,
      email = :email
    where id = :id
  </query>,
  {
    id: new QueryParam(id, "integer"),
    name: new QueryParam(name),
    email: new QueryParam(email)
  }
);

There's still an extra layer in there (i.e. the Query type and the <query> element), but the SQL is far more cleanly differentiated from the javascript, which is a big plus.  I've updated the core and sample application in Subversion with the changes to allow this syntax (the string-based syntax is still supported), along with various other little changes, including a full import of the browser-agnostic portions of Prototype (Object, Array, Hash, String, Template, etc.).

I also tried the "add the execute method to the XML class" route that I wrote about, and that doesn't work.  It seems that the E4X class (XML, XMLList, etc.) are sealed and can't have additional stuff added to them.  That's a bummer, but such is life.

2 Responses to “E4X and Prototype Goodness”


  1. 1 Yakov Fain

    The fact that some classes are sealed in Flex should not stop you.
    Create your own one-liner version when needed, i.e.

    dynamic class MyXMLList extends XMLList{}

    Now you can do whatever you want with MyXMLList.

  2. 2 barneyb

    Yakov,

    While that'll work for things created with a constructor, it won't work for literals.

    new MyXML().customMethod(); // would work
    stuff.customMethod(); // no dice

    The latter syntax is the one I'm particularly interested in, because it's transparent. You could also use a hybrid to make it work:

    new MyXML(stuff).customMethod();

    Of course, that's not any better than what I've got already:

    new Query().execute();

Leave a Reply