Wednesday, February 3, 2016

writing an executable in javascipt

Hi,

today I played around with javascript and its possibilities. To execute js in the browser was a quite non-innovative approach. That windows-8/10 apps can be written in js was also not new to me.The missing element to cover all kinds of applications was the desktop application. After 10 seconds of google-ing I found out that this works too. Even better, it works in combination with the .net framework which opens up a lot of possibilities.

The following code snippets show my test case. The resources I used were: http://www.phpied.com/make-your-javascript-a-windows-exe/ and additionally to check for the ability to use WPF components (yes that works too) https://social.msdn.microsoft.com/Forums/vstudio/en-US/bb41013f-e915-4743-81b0-8bea2d9acebb/jscriptnet-wpf?forum=netfxjscript .

make.bat
@echo off
del program.exe
"c:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc" "program.js"
program.exe

program.js
import System;
import System.Windows.Forms;
function outputMessageBox(text) {
 MessageBox.Show(text, "output message");
};
 
function output(text) {
 Console.Write(text);
};
 
output('hello world');
outputMessageBox('hi');


I am looking forward to find a use case for it :-)

kind regards,
Daniel

No comments: