Notes on Code Translation to JavaScript
This help page describes details particular to code translation using the CodeGeneration[JavaScript] function. For general information applicable to all the functions in the CodeGeneration package, see CodeGeneration/Details.
Description
The JavaScript code generated by CodeGeneration[JavaScript] is valid for JavaScript 2 as defined by the JavaScript Language Specification.
In addition to the functions listed on the CodeGeneration/Details help page, the following Maple functions are recognized by CodeGeneration[JavaScript]: cat, ceil, floor, and if (operator form).
If the parameter to CodeGeneration[JavaScript] is a procedure, the output is embedded in a class CodeGenerationClass so that it can be included easily in another JavaScript program.
Note that JavaScript does not have equivalents for the hyperbolic trigonometric functions, so CodeGeneration[JavaScript] expresses them in terms of exponential functions.
Since there are no equivalents for sign, and signum in JavaScript, CodeGeneration[JavaScript] translates them to expressions involving the conditional operator.
The functions mod, modp, and mods are all translated to JavaScript expressions using the modulus operator %.
Note: The behavior of these functions is inconsistent with the behavior of % for some values of the arguments.
Because Maple expressions involving powers greater than 2 are translated into Math.pow function calls, the automatic type deduction system may not be able to deduce the most appropriate type in all cases.
CodeGeneration[JavaScript] translates printf statements to System.out calls, but performs only limited analysis of the printf format string. Thus some formatting instructions (for example, precision for floats) are ignored in translation.
Ranges of Maple Arrays and rtables are adjusted so that the resulting JavaScript arrays start with index 0.
A Maple module is translated to a JavaScript class, with module members mapped to static class members. Exports of the module are translated as public methods or fields in the JavaScript class, while variables local to the module are translated as private methods or fields. All class members are made static.
See Also
CodeGeneration
CodeGeneration/Details
CodeGeneration[JavaScript]
Download Help Document