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.
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 .
In JavaScript, function parameters default to undefined . However, it's often useful to set a different default value.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With