12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- {
- title: 'Embedded Javascript',
- crumbs: [
- { "User's Guide": '../users/' },
- ],
- }
- <h1>Embedded Javascript</h1>
-
- <p>GoAhead provides an embedded version of Javascript for use in JST pages. As the full Javascript 6
- specification is quite a large language, GoAhead's implements a small subset suitable for embedded use.
- GoAhead Javascript™ is a strict subset of Javascript and implements the essential elements of the language.
- It also provides the engine for JST pages to enable the easy creation of dynamic web pages.</p>
- <p>A standalone product, <a href="https://embedthis.com/ejscript/">Embedthis Ejscript™</a> more
- fully supports the latest Javascript 6 specification and when used
- with the <a href="https://embedthis.com/appweb/">Appweb</a> embedded web server
- is an alternative to GoAhead if you have sufficient memory available.</p>
-
- <p>When GoAhead Javascript is used inside a JST web page, it consists of a script within JST delimiters.
- The basic format is:</p>
- <pre class="ui code segment"><% function(arguments, ...); %></pre>
- <p>Javascript functions are created by the jsSetGlobalFunction. When the function is evaluated, the
- corresponding C procedure that implements the Javascript function is called.</p>
- <p>GoAhead Javascript implements the following Javascript elements:</p>
- <ul>
- <li>Case sensitivity</li>
- <li>White space</li>
- <li>Semicolons</li>
- <li>Comments</li>
- <li>Identifiers</li>
- <li>Data types including numbers, booleans, and strings with backslash characters</li>
- <li>Full expressions</li>
- <li>If/else, for, return</li>
- <li>Global function calls</li>
- </ul>
- <p>The following language elements are not implemented:</p>
- <ul>
- <li>Arrays</li>
- <li>Objects</li>
- <li>Labeled statements</li>
- <li>Control flow statements including: break, case, continue, default, do/while, export, for/in, function,
- import,switch, var, while, and with</li>
- <li>Regular expressions</li>
- </ul>
- <p>Javascript scripts can span multiple lines by using "\" as the last character on the preceding line. When
- used in JST pages, function arguments can contain any query variable defined in either the URL query string or
- the standard variable set. URL query strings are automatically decoded, and Javascript variables are defined to
- the decoded query value. For example, to parse the name and address encoded as a query string in a URL, use the
- following code:</p>
- <pre class="ui code segment">http://localhost/mypage?name=smith&age=35</pre>
- <pre class="ui code segment">
- int myAspProcedure(Webs wp, int argc, char **argv) {
- char *name = websGetVar(wp, "name", "undefined");
- char *age = websGetVar(wp, "age", "undefined");
- websWrite(wp, "Name %s, Age %s", name, age);
- }
- </pre>
- <p>Javascript procedures are registered by using the <a
- href="../ref/api/goahead.html#group___webs_1ga4db3f71301ed08e4f8d3c466d3632ea1">websDefineJst</a> API.
- This publishes a C procedure as a Javascript global function. For example:</p>
- <pre class="ui code segment">
- extern int outputMyTable(int ejid, Webs wp, int argc, char **argv);
- websDefineJst("outputTable", outputMyTable);
- </pre>
- <p>The websDefineJst call publishes the Javascript command "outputTable" and links it to the
- outputMyTable C procedure. When an JST page is requested by the user's browser, any JST
- Javascript which uses the outputTable command will cause the outputMyTable to be called with
- the relevant arguments.
|