1

I was looking around at how to make javascript run more efficiently as compiled code. I came across jscript.net in this question jscript

Whilst I was not really interested in using it to hide my JavaScript logic I was interested in the fact it resulted in compiled code.

I tried Googling around but I all I seem to get was that it was an old idea from Microsoft dating around framework 1.1.

Also, i got 2 camps of opinions saying they hated it because it was a nightmare to debug and the other side saying it improved performance.

I have not found much more info than that.

So, if I am not too concerned about debugging (for the moment) should I consider using jscript.net for the compiled faster execution of code? Is there a more modern alternative to this for the framework I am using or should I just not consider it at all?

Finally, {sorry} are there any code samples/instruction as to how to implement it?

Community
  • 1
  • 1
Andrew Simpson
  • 6,883
  • 11
  • 79
  • 179

2 Answers2

2

I'm developing websites with .html pages (html5 + jquery + bootstrap) in the client, web handlers (.ashx files with JScript .NET v10) in the server side.

The QuickSharp mini-ide has support for JScript .NET and is simple and FAST!

Justin Rogers' book "Microsoft JScript NET Programming" is a must.

aMarCruz
  • 2,434
  • 1
  • 16
  • 14
1

Lately I'm using jscript.net a lot (along with the 'old' jscript that comes with WSH).

But never use it with the Visual Studio (you probably already found this).But just with the simple notepad++.

And here's what makes the jscript so great for me:

  1. It's available on every windows system (even the most ancient XP machines have some .net framework with them) , because every .net framework comes with jscript compiler.
  2. Because of the jscript directives it's perfect for 'built-in' batch file (example bellow)
  3. There's a lot of javascript code that can be used almost directly in jscript.net. After all javascript is the most popular programming language in the world.
  4. It has .net power behind it

And what I don't like:

  1. Looks like it's a little bit abandoned by Microsoft.
  2. Even on MSDN there the code snippets/examples are very few.Despite that in 90% of the cases it's easy to re-write the C# code to Jscript.
  3. There are some cool features that are missing in jscript.net but are available in other two native .net langiages (vb and cs) - dll import , generics ..

And here's how I use jscript.net in the notepad :

@if (@X)==(@Y) @end /****** silent jscript comment ******

@echo off
::::::::::::::::::::::::::::::::::::
:::       compile the script    ::::
::::::::::::::::::::::::::::::::::::
setlocal

:: remove the rem bellow when you fell your code is ready to use
rem if exist "%~n0.exe" goto :skip_compilation

:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
    if exist "%%v\jsc.exe" (
        rem :: the javascript.net compiler
        set "jsc=%%~dpsnfxv\jsc.exe"
        goto :break_loop
    )
)
echo jsc.exe not found && exit /b 0
:break_loop



call %jsc% /nologo /out:"%~n0.exe" "%~f0" 
::::::::::::::::::::::::::::::::::::
:::       end of compilation    ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation

::
::::::::::
"%~n0.exe" %*
::::::::
::
endlocal
exit /b 0

****** end of jscript comment ******/

import System;
Console.WriteLine( "Boo" );
Console.WriteLine("Press any key to continue...");
Console.ReadKey();

You can save this as a .bat file and run it.It will compile itself and will start.As whole you don't to worry to much for the code inside comments and you can use it just as a pattern.

npocmaka
  • 55,367
  • 18
  • 148
  • 187