JS++

I recently learned about JS++. Although it is presently only available for Windows and Linux systems, it looks interesting. Essentially, JS++ is a compiler which takes code and generates JavaScript. However, resulting JavaScript is much more structured than one would normally write. There is a fair amount of documentation (however, these pages indicate they are presently out of synch with the current implementation).

The following description is taken directly from their website (and is why I think this implementation has possibilities).

JS++ expands the original JavaScript language with types, classes, and other new features. Thus, if you already know JavaScript, you already know JS++; just pick and choose which features you want to “add on” to your existing code. One of the unique features of JS++ is its ability to perform sound type checking. In other words, when you declare types for your variables in JS++, the types are guaranteed to always be correct at compile time and runtime. A variable declared as int will always remain an int at both compile time and runtime, a variable declared as unsigned short will always remain an unsigned short at compile time and runtime, and a variable declared as an Employee class will always remain an Employee object at both compile time and runtime. Previous systems could not guarantee your types would not transform at runtime, and there could be instances where a string could “morph” into a number, function, null, or any other type during application execution.

Ok, let’s learn a little more about JS++. Note that I am just scratching the surface in this weblog post. If enough readers express interest in more in depth analyses, I may include that in the future.

First, I installed this on a Windows Server 2012 R2 operating system (since there is presently not a Mac version). You simply download, virus check, and install the .exe file. Once installed, you open the command prompt and enter js++ –version. Assuming all works as anticipated, you will see a screen like the following.

Screen capture of JS++ version

 

In the above case, this is the most recent version of JS++. You will also note that I am working in a Scripts/JS folder so I can keep all my code organized for these examples.

The first file I created is Example01.jspp (note the extension). I am using Brackets to display the contents below.

 

Example JSPP file

I next compiled the above file (using the command shell and the command js++ example01.jspp. The results are shown below.

 

Compiling JSPP

 

The resulting jspp.js file does not readily pass JSLint (but I have this set to very strict standards).

 

JSLint in Brackets has issues

 

As noted, there are some observed problems (most of these are relatively minor and likely due to my settings for JSLint in Brackets). I would expect the version 1.0 of JS++ will have addressed these sorts of issues.

One next creates a bit of HTML and references the JS file as shown below.

 

Initial HTML code referencing created JS file

 

The resulting web page is shown in the Chrome browser below.

Resulting web page

 

Note this is just the beginning of what you can do. There are tutorials on using the JS++ type system and much more. I wanted to introduce readers to this tool. I think it has possibilities. Given that it may be some time before ES 6 is readily supported in most browsers, this may also prove to be a useful intermediate approach to writing more structured JavaScript.

I am curious if you have tried JS++ (or plan to experiment with it). As always, I look forward to your comments.

 

 

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial