getting started with jsolait 2.0
Getting started with jsolait is very simple.
Download jsolait and unpack it in a folder along with an html file.
The html file should look as follows:
<html>
<head>
<script type="text/javascript" src="./jsolait/jsolait.js"></script>
<script type="text/javascript" src="./tutorial.js"></script>
</head>
<body>
</body>
</html>
The file jsolait.js contains the core functionality of jsolait and is the minimum of files you need to include in the html file. As you see above though, we added another file which contains code to demonstrate some of jsolait's functionality. The following is the content of the file tutorial.js:
alert(s1);
var s2 = "The number %d as a hexadecimal is %X.".format(123456789,123456789);
alert(s2);
The example shows jsolait's string formating functionality. It is very similar to pythons % operator or sprintf() functionality from C/C++. All %s, %f, %X in a String are replaced by converting the values passed into the format method to a desired format. There are more formating specifiers than %s, %f, %X. Please see the documentation for the stringformat module for more information.
using modules
JavaScript unfortunatly does not support the concept of modules or packages. But it is possible to add this missing feature and that's what jsolait does. To use modules you need to import them. Jsolait will take care of loading the module and resolve any dependencies that might occur. Here an example (you could place it in the tutorial.js file:
var codecs = imprt("codecs");
alert(codecs.listEncoders());
var s1 = "Hello jsolait";
var s2 = s1.encode("base64");
alert("'%s' encoded using base64 is '%s'".format(s1,s2));
The example above imports a module called 'codecs' which is one of the modules that comes as part of jsolait. To import that module the imprt() function is usesd. It is a global function supplied by jsolait. When called it will determine wether or not the module has already been loaded or not. In the later case it will try to load the module's source file. If the module has then been loaded it will be returned. If imprt() fails an Exception is thrown containing information of why it failed.
Next lets explore how to create a module.
