JavaScript in Synchronet

Synchronet uses Mozilla's JavaScript engine for its preferred local scripting environment.

You can learn about the core JavaScript language and object model from the following documents:

JavaScript is an established, mature scripting language syntactically similar to C++ and Java.

JavaScript is not Java.

The ECMA and ISO standards organizations have standardized the core JavaScript language in ECMA-262 (ECMAScript) and ISO-16262.

Baja and JavaScript

Baja is the original scripting language of Synchronet (introduced in v2.0), used to create Synchronet-specific modules and command shells. Baja was originally designed as a simple BASIC-like language for controlling the display of menus and command prompts, accepting commands from the user and passing on control to high-level BBS functions. Over the years, Baja has been extended and enhanced to allow a high-level of functionality, but it was never going to reach the power and flexibility of JavaScript.

For example Baja modules and command shells, see the .src files in your Synchronet exec directory.

For the foreseeable future Baja modules and command-shells will continue to be supported in Synchronet, but sysops and developers are encouraged to use JavaScript instead of Baja moving forward. With very few exceptions, everything that can be done in a Baja module can be done in a JavaScript module, and much much more.

Eventually, all the stock command-shells and external modules will be converted to JavaScript.

JavaScript Files

JavaScript files are just ASCII text files. They are normally named with a .js file extension and located in your Synchronet exec directory or with a .ssjs and located in your Synchronet web hierarchy. JavaScript files do not need to be compiled. JavaScript files are loaded into memory at the time of execution, so a change to a JavaScript file will take effect the next time that file is executed (no recycling of servers is normally required).

For example JavaScript modules and services, see the .js files in your Synchronet exec directory.

Modified stock .js files should be placed in your Synchronet mods directory to prevent over-writing by future upgrades.

Integration

JavaScript files can be executed from:

From the Terminal Server, a JavaScript file is executed on a native command-line by placing a question mark (?) at the beginning of the command-line before the JavaScript file name (in SCFG). It is not necessary to specify the .js portion of the file name on the command-line. For example, the command-line to execute the file exec/newslink.js would be "?newslink" or "?newslink.js".

From within a Baja module, a JavaScript file may be executed using the following Baja code:
exec "?modname" where modname is the JavaScript file.

Object Model (methods and properties)

Synchronet has its own constantly evolving JavaScript object model, not to be confused with the Document Object Model (DOM) used in web browsers. In order to fully understand the capabilities of JavaScript modules in Synchronet, you must familiarize yourself with Core JavaScript as well as the Synchronet JavaScript Object Model.

$Id: js.html,v 1.9 2011/10/21 02:35:04 rswindell Exp $