7

I'm using some existing code and there is this line I don't understand. I only know that default can be used as part of a swtich statement, but didn't know if there is some other use for it. The code works. It's part of TurkIt which is used for running programs through Amazon's MTurk.

function getQuestion(numA, numB) {
    default xml namespace = "http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd";
    var q = <QuestionForm> ...

See the default before the xml namespace statement.

Thomas
  • 43,637
  • 12
  • 109
  • 140
user994165
  • 9,146
  • 30
  • 98
  • 165
  • Works how? What does the second line do? As it is shown - it should not work. Are you sure that there are no `_` between `default`, `xml` and `namespace`? – ZenMaster Oct 30 '11 at 19:12
  • the second line is a `SyntaxError` as well, if this works at all it's because it's being transformed to real javascript not being run as is. – Esailija Oct 30 '11 at 19:14
  • @Esailija - Not getting a syntax here in FF 7.0.1: http://jsfiddle.net/Ka833/ – Jared Farrish Oct 30 '11 at 19:16
  • @JaredFarrish I think it's FF eval-powered console acting up again. It does fail in Chrome console and in a standalone HTML. – ZenMaster Oct 30 '11 at 19:18
  • @ZenMaster - I get a `invalid default XML namespace` [here](http://jsfiddle.net/Ka833/1/), which implies there is something going on, maybe Firefox-specific? – Jared Farrish Oct 30 '11 at 19:21
  • @JaredFarrish see John's answer. Indeed there is. – ZenMaster Oct 30 '11 at 19:22

1 Answers1

14

default xml namespace is an ECMAScript for XML (E4X) directive.

E4X is an extension to ECMAScript that lets you treat XML like a primitive type (that's also what's going on with the var q = <QuestionForm> ... part). The default xml namespace directive sets (As you might expect) the default XML namespace for the same scope as the directive.

Mozilla's SpiderMonkey (the engine used by Firefox and other Gecko browsers) and Rhino are the only JavaScript engines I know of that support E4X, but the ECMAScript-based ActionScript 3 also does. I assume TurkIt is designed to run on Rhino.

John Flatness
  • 32,469
  • 5
  • 79
  • 81