Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Mozilla E4X

Brendan Eich

Chief Architect, Mozilla

JavaScript

E4X

Mapping XML to JS

Mapping XML to JS (2)

Mapping XML to JS (3)

Familiar operators

New operators

XML literals

Namespaces and QNames

Oddments, bugs, and fun stuff

  • ECMA-357 does not throw ReferenceError for undefined XML names
    • * => undefined
    • @oops => undefined
    • @*::* => undefined
  • What were they thinking?
  • May have been motivated by filtering predicate operator
    • applied to inhomogeneous data
    • but you can use .. to homogenize
  • Fixed in ISO version of spec

Oddments, bugs, and fun stuff (2)

  • Expandos make markup composition a snap!
  • Just start appending extra property tiers:
    var html = <html/>;
    html.head.title = "My Page Title";
    html.body.@bgcolor = "#e4e4e4";
    html.body.form.@name = "myform";
    html.body.form.@action = "someurl.jss";
    html.body.form.@method = "post";
    html.body.form.@onclick = "return somejs();";
    html.body.form.input[0] = "";
    html.body.form.input[0].@name = "test";
    

Oddments, bugs, and fun stuff (3)

  • Results in this XML:
    <html>
      <head>
        <title>My Page Title</title>
      </head>
      <body bgcolor="#e4e4e4">
        <form name="myform" action="someurl.jss"
              method="post" onclick="return somejs();">
          <input name="test"></input>
        </form>
      </body>
    </html>
    

Future work

  • Disambiguate identifiers in filtering predicates and with
  • Generalize filtering predicate and descendant operators to other types
  • Namespaces and QNames also generalized in Edition 4 (JavaScript 2)
  • XML methods are hidden in a special namespace
    • You can't extract m = x.toXMLString; and call m later
    • SpiderMonkey adds m = x.function::toXMLString for this
  • Should JS have a list type and generators?