# Embedded JavaScript GoAhead developed an embedded version of JavaScript called Ejscript™. As JavaScript 1.2 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 to Active Server Pages (ASP) to allow the easy creation of dynamic web pages. When JavaScript is used inside an ASP web page, it consists of a script within ASP delimiters. The basic format is:
            <% 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. Ejscript implements the following JavaScript elements: Case sensitivity White space Semicolons Comments Identifiers Data types including numbers, booleans, 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, 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

    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. ## See Also Active Server Pages, GoForms™, websSecurityHandler, websUrlHandlerDefine

#