Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript default keyword

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.

like image 951
user994165 Avatar asked Oct 30 '11 19:10

user994165


People also ask

What is the default keyword in JavaScript?

The default keyword specifies some code to run if there is no case match in the switch. Note: if the default keyword is used as the last statement in a switch block, it does not need a break .

What is the default value of a variable in JavaScript?

In JavaScript, function parameters default to undefined . However, it's often useful to set a different default value.

What is export in JavaScript?

The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the import declaration or dynamic import.


1 Answers

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.

like image 191
John Flatness Avatar answered Oct 08 '22 08:10

John Flatness