js.html 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {
  2. title: 'Embedded Javascript',
  3. crumbs: [
  4. { "User's Guide": '../users/' },
  5. ],
  6. }
  7. <h1>Embedded Javascript</h1>
  8. <p>GoAhead provides an embedded version of Javascript for use in JST pages. As the full Javascript 6
  9. specification is quite a large language, GoAhead's implements a small subset suitable for embedded use.
  10. GoAhead Javascript&trade; is a strict subset of Javascript and implements the essential elements of the language.
  11. It also provides the engine for JST pages to enable the easy creation of dynamic web pages.</p>
  12. <p>A standalone product, <a href="https://embedthis.com/ejscript/">Embedthis Ejscript&trade;</a> more
  13. fully supports the latest Javascript 6 specification and when used
  14. with the <a href="https://embedthis.com/appweb/">Appweb</a> embedded web server
  15. is an alternative to GoAhead if you have sufficient memory available.</p>
  16. <p>When GoAhead Javascript is used inside a JST web page, it consists of a script within JST delimiters.
  17. The basic format is:</p>
  18. <pre class="ui code segment">&lt;% function(arguments, ...); %&gt;</pre>
  19. <p>Javascript functions are created by the jsSetGlobalFunction. When the function is evaluated, the
  20. corresponding C procedure that implements the Javascript function is called.</p>
  21. <p>GoAhead Javascript implements the following Javascript elements:</p>
  22. <ul>
  23. <li>Case sensitivity</li>
  24. <li>White space</li>
  25. <li>Semicolons</li>
  26. <li>Comments</li>
  27. <li>Identifiers</li>
  28. <li>Data types including numbers, booleans, and strings with backslash characters</li>
  29. <li>Full expressions</li>
  30. <li>If/else, for, return</li>
  31. <li>Global function calls</li>
  32. </ul>
  33. <p>The following language elements are not implemented:</p>
  34. <ul>
  35. <li>Arrays</li>
  36. <li>Objects</li>
  37. <li>Labeled statements</li>
  38. <li>Control flow statements including: break, case, continue, default, do/while, export, for/in, function,
  39. import,switch, var, while, and with</li>
  40. <li>Regular expressions</li>
  41. </ul>
  42. <p>Javascript scripts can span multiple lines by using "\" as the last character on the preceding line. When
  43. used in JST pages, function arguments can contain any query variable defined in either the URL query string or
  44. the standard variable set. URL query strings are automatically decoded, and Javascript variables are defined to
  45. the decoded query value. For example, to parse the name and address encoded as a query string in a URL, use the
  46. following code:</p>
  47. <pre class="ui code segment">http://localhost/mypage?name=smith&amp;age=35</pre>
  48. <pre class="ui code segment">
  49. int myAspProcedure(Webs wp, int argc, char **argv) {
  50. char *name = websGetVar(wp, "name", "undefined");
  51. char *age = websGetVar(wp, "age", "undefined");
  52. websWrite(wp, "Name %s, Age %s", name, age);
  53. }
  54. </pre>
  55. <p>Javascript procedures are registered by using the <a
  56. href="../ref/api/goahead.html#group___webs_1ga4db3f71301ed08e4f8d3c466d3632ea1">websDefineJst</a> API.
  57. This publishes a C procedure as a Javascript global function. For example:</p>
  58. <pre class="ui code segment">
  59. extern int outputMyTable(int ejid, Webs wp, int argc, char **argv);
  60. websDefineJst("outputTable", outputMyTable);
  61. </pre>
  62. <p>The websDefineJst call publishes the Javascript command "outputTable" and links it to the
  63. outputMyTable C procedure. When an JST page is requested by the user's browser, any JST
  64. Javascript which uses the outputTable command will cause the outputMyTable to be called with
  65. the relevant arguments.