Using Embedded JavaScript™

The version of JavaScript implemented in AppWeb is a small subset suitable for embedded systems. As JavaScript 1.2 is now quite a large language, its size prohibits its use in most embedded devices. Embedded JavaScript is designed to solve this dilemma. It is a strict subset of JavaScript that implements the essential elements of the language and is extensible by the user to support new functions.

Embedded JavaScript is used by Embedded Server Pages to allow access to HTTP variables and to get dynamic data for presentation to the client's browser. When used inside an ESP web page, it consists of a script within ESP tag delimiters.

Features

Embedded JavaScript implements the following JavaScript language elements:

  • Case sensitivity
  • White space
  • Semicolons
  • Comments
  • Identifiers
  • Data types including numbers, booleans, strings with quoted backslash characters
  • Full expressions
  • If/else, for, return
  • Global function calls

The following language elements are not implemented:

  • Arrays
  • Objects
  • Exceptions
  • Labeled statements
  • Control flow statements including: break, case, continue, default, do/while, export, for/in, function, import, switch, var, while, with
  • Regular expressions

The supported operators are:

  • <  <=  ==  !=  >  >=
  • +  -  /  %
  • <<  >>
  • ++  --

The supported conditional operators are:

  • &&  ||
  • !

Embedded JavaScript is multithreaded and will support multiple simultaneous instances. When used by ESP, each JavaScript session has its own local variable store and can share data via the session data store.

JavaScript Procedures

The JavaScript capabilities may be extended by publishing new JavaScript functions. JavaScript functions may be created by instantiating a n object that implements the MprEjsProc subclass or by calling the maDefineEsp() C function to link a C function to a JavaScript procedure. See the Programmers Reference for more details.

Examples

Basic Iteration

var i, j;

j = 0;
for (i = 0; i < 10; i++) {
write("iteration, " + i + "\n");
j = j + i;
}
write("end\n");

 

Including JavaScript libraries (Server-side)

<% include("inc.js"); %>

 

ESP Variable Access

<% i=2; %>

Access value using equals: <% = i %>


Access value using atat: @@i


Scripted HTML


Scripted Iteration of HTML



<% for (i = 0; i < 5; i++) { %>

Para: @@i


<% } %>




© Mbedthis Software LLC, 2003-2204. All rights reserved. Mbedthis is a trademark of Mbedthis Software LLC.