Overview
JS Console was developed as a Mozilla extension to ease the developer work.
Even if you're an expert in JavaScript coding, you sometimes need to quickly verify some code construction or try an algorithm.
And if you're a newbie, you'll probably find JS Console very handy to try some exemples and soon become a JavaScript Guru.
Oddly enough, no such tool actually exists in the Mozilla community. Of course we have the Mozilla JavaScript Console, accessible thru the Web development menu, but seriously, do you use it to evaluate a code snippet?
JS Console fills the gap: not only you can type in hundreds or thousands lines of code to evaluate, but you can also save this code to a file and later reload it to make some change.
At any time, you can evaluate the code you typed in an have an immediate result of the evaluation.
If any exception is thrown by your code, it is displayed in the Errors panel and you can save the error message to a file.
You can insert debugging instructions in your code (using the __SETOUT__ function) and those instructions will be displayed in another panel: the Output panel, which you can save too.
All commands are gathered in a contextual menu which mimizes mouse gestures. So you have a simple but powerful tool to exercize you coding skills (there are keyboard shortcuts for many of these menu entries).
JS Console is designed according to the
Object Oriented Programing paradigm: functionnalities come from classes and if you browse thru the code you'll see that OOP can be gracefully implemented in JavaScript.
JS Console classes relies on a standalone Mozilla extension,
Mozlib (installed with JS Console package), which provides useful general purposes classes:
- an XPCOM wrapper singleton class to give access to any XPCOM component or interface (JS Console uses it everywhere),
- a stdout class to dump messages to the shell console (if you launch Mozilla from a shell console),
- a DOM monitor class to ease DOM elements management,
- a full set of classes for local file I/O (used by load and save commands),
- a full set of classes for RDF datasources management,
- a prompt class to easily call the different kinds of interactive alert boxes,
- a script loader class to evaluate the content of any script file in the middle of your code (even in conditional constructs). So you can easily use any library you have already developed.
Mozlib class instances can be used anywhere and directly within the code you want to evaluate.
JS Console comes with its own set of preferences to customize its GUI: each panel can adopt a background color, text color, font an font-size of its own. You can define a default path for accessing files loaded and saved from every panel.
The result of any code evaluation has a header to identify the code run: this is a string defined by a preference setting. This string can contain a fragment of code (enclosed in backtick characters) evaluated before displaying the result. This code fragment can be used for instance to stamp the result.
To help you debug your code, you can use the __TRACE__ function which dumps the content of the JavaScript stack. This gives you the function name (with its source file and line number) which is calling this __TRACE__ function, then the function calling that caller function, and so on up to the level you choose by setting the last function call you want to trace.
You can also use the __ASSERT__ methods of the unit testing framework to develop your code applying the test first design methodology.
Another useful feature is the code fragment store, a list of lines of code (managed as an RDF file automatically put in the user profile folder) to which you can add (and later remove) your most frequently used code fragments. These fragments can be inserted anywhere in the code panel.
JS Console has also an help panel to detail its functionalities and commands.
Further improvements could be added to JS Console:
- extend the simple API giving one shot access to useful functions for editing,
- more code library (Mozlib),
- etc.
Features
- Import script file(s) function
- JavaScript API for local file I/O, RDF, error and XPCOM libraries
- Full stack trace function for debugging
- Unit testing framework for test first design development
- Code loading from local file system (automatic reload of the last loaded file at startup
- Code, output, errors, and unit testing panel content saving to local file system
- Code fragments store for fast code snippet insertion
- Code execution timer
- Comprehensive help
- GUI preferences
Use the context menu to navigate in the documentation pages