Introduction to JScript.NET


We have been hearing the announcement from Microsoft right from PDC2000 that they have realsed new languages viz. C#, VB.NET and JScript.NET. This artice of mine is going to introduce to you JScript.NET.

Jscript's association with the ECMAScript standard has helped its success considerably, this has led to a close compatibality with JavaScript. The most dramatic impact on performance in JScript.NET is that it is a true compiled language, which makes it possible to achieve performance comparable to that of C# and Visual Basic.NET. As JScript is a part of .NET it automatically benefits from all the goodies .NET offers.

.NET ships with a compiler for JScript.NET called jsc Jscript can be compiled as a .exe or a .dll (default), Jscript can also be used in ASP.NET pages and create web services by specifying "Language=JScript".

Creating a Simple .exe using JScript Hello.js

//Copy this line in a file Hello.js
//Compile it as jsc /exe Hello.js to produce Hello.exe
print("Hello From Jscript Exe");

Creating a Simple Class
in Jscript : Class.js

//Copy in a file Class.js
//Compile it as jsc /exe class.js to produce class.exe
class Class1
{
function sayHi()
{
return "Hi from JScript Class";
}
}
var o : Class1 =
new Class1;
print(o.sayHi()); 

A Bit of OOPS
in JScript.NET : class1.js

//Copy in a file Class1.js
//Compile it as jsc /exe Class1.js to produce class1.exe
class Class1
{
function sayHi()
{
return "Hi from JScript Class";
}


class c2 extends Class1
{
protected var name : String; //variable of type string
function get fname() : String //property get (acessor)
{
return this.name;
}
function
set fname(newName : String) //property let (mutator)
{
this.name = newName;
}
}
var o : c2 =
new c2;
print(o.sayHi());
o.fname = "Manish";
print(o.fname); 

Creating a Simple WebService
in JScript.NET : JSweb.asmx

<%@ WebService Language ="JScript" Class="MyJS" % >
import System.Web.Services;
class MyJS extends WebService
{
WebMethodAttribute function sayHi() : String
{
return "Hi from a JScript.NET web service";
}


JScript.NET blends seemlessly in the .NET framwework and so will other languages like SmallTalk, FujitsuCOBOL and other .NET compatible languages.

Up Next
    Ebook Download
    View all
    Learn
    View all