<

JavaScript Compiler for free!

0 Points
164 Views
1 Endorsement
Last Modified:
Zvonko
CERTIFIED EXPERT
zvonko@gmail.com ...
If you look up the rankings for most popular programming languages, you will find JavaScript at top rankings. But it is only an interpreter language. Would it not be fine to have some JavaScript compiler to create executables from JavaScript? There is one on your Windows computer already installed!

Believe me or not, I have started learning JavaScript on IBM Mainframe. And the best resource for learning JavaScript in that time was, guess? Experts Exchange!
That was in 1997. Check out my profile for proof  ;-)


I have looked for a compiler for standalone JavaScript executables and found only difficult tools.
But a perfect JavaScript compiler is already on every Windows computer! It is part of the Microsoft.NET environment.


All Windows computers do have a Microsoft.NET environment. Part of this environment are the compilers for VB.net, C# and JScript.Net
Here you can lookup the diferences betwean JavaScript as know from browsers and JScript.Net:
https://en.wikipedia.org/wiki/JScript_.NET .


I use this compiler on Windows 10 to create EXE files from a JavaScript source:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\jsc.exe


If you create the following batch file jsc.cmd, you can call the JavaScript compiler without changing your PATH settings.
The jsc.cmd file looks like this:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\jsc.exe" /debug %*


Now you have everything you need to start JavaScript programming on Windows.


But what can you do with this JavaScript compiler? 


OK, the compiler environment is Microsoft.NET and there is almost no information about using JavaScript in Dot.NET.

Therefore, you have to adopt the information for C# to JavaScript.

You can use all Dot.NET libraries that are for C# in the same way for JavaScript.


For example, to use file read and write, lookup C# file read and write and see what libraries you need for C# and use the same libraries for JavaScript.


With JavaScript Dot.NET you have access to files system, to Zip compression, to Registry, Office Tools, like WordExcel and others, to SQL data, to XML structure, to Web Services and even to SharePoint servers.


The fine thing is that JavaScript has built-in features for Regular Expressions and for Associative Arrays where C# needs extra libraries.


And best of all: in EXE you can use at runtime the JavaScript eval() function! That does say, your EXE can read a JavaScript text file and run it without compilation. I have used that backdoor for configuration purposes but have switched lately to XML config files.


Dont get me wrong, I would never recommand to use JavaScript for big application programming. But I am comming from mainframe Systems Programmer corner. That will say, I do not programm monolith applications but I do reuse small tools for single task and combine them to convient big applications.
For combining the single task tools is the most important programming feature the String handling of the programming language. And voila! That is JavaScript.
You can create your own single task tools with JavaScript and you can manage this tasks with JavaScript. That is how I use it.
I use it for example for our SharePoint automated mainenance tasks to crosscheck Document Libraries and update Person fields in them.


Now is the time for the famous Hello World!

Here we go!


Create this source file: hello.js

// hello.js
// say Hello to World : )
print("Hello world!");

print("Current time: "+(new Date()));


Compile it with upper jsc.cmd batch file like this:

jsc.cmd hello.js


You will get this file:  hello.exe

The file hellp.pdb is for debugging purposes.


That's it!

 

The is the first article in a series of JavaScript Compiler articles.

Next articles will be about usefull IDEs, examples how to use File System, SQL Data, XML coding, Web Services and my favorite, how to update XML files in a SharePoint Document Library from DOS command line.


Happy coding,
Zvonko


1
Author:Zvonko
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free