Embedded JavaScript
GoAhead provides an embedded version of JavaScript with WebServer called Ejscript™. As the full JavaScript 1.2 specification is now quite a large language, its size prohibits its use in most embedded devices. GoAhead's embedded JavaScript is designed to solve this dilemma. Ejscript™ is a strict subset of JavaScript and implements the essential elements of the language. Ejscript also interfaces with Active Server Pages (ASP) to allow the easy creation of dynamic Web pages.
GoAhead 提供一个嵌入式版本的JavaScript ,即Ejscript。因为完整版的JavaScript 1.2现在是一个内容比较庞大的语言,它的大小阻止了它在嵌入式设备上的使用。GoAhead嵌入式JavaScript 就是为了解决这个尴尬的局面。Ejscript是一个严格的JavaScript 子集,它具备JavaScript必备的一些元素。Ejscript同样和ASP接口进行交互以创建建议的动态Web 网页。
A standalone product, Embedthis EJScript™ more fully supports the latest JavaScript 3 specification and is an alternative to the built-in WebServer support.
When JavaScript is used inside an ASP Web page, it consists of a script within ASP delimiters. The basic format is:
Embedthis EJScript作为一个独立的产品更加充分的支持最新的JavaScript 3,同时可以替代内置WebServer 支持。
当JavaScript 在ASP Web网页中使用的时候,脚本语言包含ASP的分隔符内。基本的格式如下:
<% function(arguments, ...); %>
JavaScript functions are created by the ejSetGlobalFunction. When the function is evaluated, the corresponding C procedure that implements the JavaScript function is called.
ejSetGlobalFunction可以创建JavaScript 功能。当功能被评估的时候,相应的处理处理JavaScript 函数C程序就会被调用。
Ejscript implements the following JavaScript elements:Ejscript 包含以下一些JavaScript 元素
· Case sensitivity大小写敏感
· White space空白字符
· Semicolons分号
· Comments逗号
· Identifiers标识符
· Data types including numbers, booleans, and strings with backslash characters数据类型
· Full expressions 充分表达式
· If/else, for, return
· Global function calls 全局函数调用
The following language elements are not implemented:
· Arrays 数组
· Objects 对象
· Labeled statements 标记语句
· Control flow statements including: break, case, continue, default, do/while, export, for/in, function, import, switch, var, while, and with 控制流
· Regular expressions 常规表达
JavaScript scripts can span multiple lines by using "" as the last character on the preceding line. When used in ASP 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:
http://localhost/mypage?name=smith&age=35
JavaScript 通过讲最后一个字符置为""来续行。当JavaScript 用于ASP页面中的时候,功能参数可以包含任何定义在URL查询字符串或者标准变量集里的变量。URL查询字符串是自动解码的,JavaScript 变量用于定义解码查询值。比如,解析URL中的一个查询字符串中的名字和地址,使用如下的代码:
int myAspProcedure(webs_t wp, int argc, char_t **argv) {
char_t *name = websGetVar(wp, "name", "undefined");
char_t *age = websGetVar(wp, "age", "undefined");
websWrite(wp, "Name %s, Age", args);
}
JavaScript procedures are registered by using the websAspDefine API. This publishes a C procedure as a JavaScript global function. For example:
extern int outputMyTable(int ejid, webs_t wp, int argc, char_t **argv);
websAspDefine("outputTable", outputMyTable);
The websAspDefine call publishes the JavaScript command "outputTable" and links it to the outputMyTable C procedure. When an ASP page is requested by the user's browser, any ASP JavaScript which uses the outputTable command will cause the outputMyTable to be called with the relevant arguments.
JavaScript 过程是通过websAspDefine API来注册的。它将一个C程序作为一个全局的JavaScript 来发布。websAspDefine 调用发布的JavaScript 命令outputTable,链接到outputMyTable C程序中。当用户请求一个ASP页面的时候,任何使用outputTable 命令的ASP JavaScript 将会调用outputMyTable 和相关的参数。