Introduction
We have been hearing the announcement from Microsoft right from PDC2000 that they have realized new languages, viz. C#, VB.NET and JScript.NET. This article of mine is going to introduce you to JScript.NET.
Jscript's association with the ECMAScript standard has helped its success considerably; this has led to a close compatibility 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 {
sayHi() {
return "Hi from JScript Class";
}
}
var o = 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 {
sayHi() {
return "Hi from JScript Class";
}
}
class c2 extends Class1 {
constructor() {
super();
this.name = ""; // variable of type string
}
get fname() { // property get (accessor)
return this.name;
}
set fname(newName) { // property set (mutator)
this.name = newName;
}
}
var o = 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 {
[WebMethod]
function sayHi() : String {
return "Hi from a JScript.NET web service";
}
}