The following provides some quick hints on how to get up to speed on JScript.NET. It assumes you already know JScript 5.x. For information on JScript 5.x, please see the documentation on the Windows Script web site.
JScript.NET runs on top of the .NET platform, so can use the features of the .NET frameworks. It also runs a lot of existing script code (we don't have 100% compatibility) so you can do pretty much all the wonderful things you used to do in 5.x along with all this new cool stuff in 7.0.
JScript.NET can be used in ASP+ as well as for creating web services, .NET components (DLLs) and stand-alone EXE programs.
For help about JScript.NET, have a look at the microsoft.public.net.jscript.general newsgroup.
For help about the .NET platform, see the NGWS SDK information that is installed as part of the .NET installation.
JScript.NET is installed as part of the .NET SDK, which you can install from http://msdn.microsoft.com/net/. Please note that the PDC release of the JScript.NET compiler is a very early version, and many things do not work yet. The beta release of the compiler will be much better!
Using the jsc compiler. Type jsc /? for help --
the output is below. Note that the default thing for JScript to do is build
a DLL; specify the /exe option to build an EXE
X:\>jsc /? Microsoft (R) JScript Compiler Version 7.00.8946 [NGWS runtime 2000.14.2016] Copyright (C) Microsoft Corp 2000. All rights reserved. jsc [options] <source files> [[options] <source files>...] Available compiler options: /? Display help /nologo Do not display compiler copyright banner /warnaserror[+|-] Treat warnings as errors /exe Generate an executable /nostdlib[+|-] Do not import standard library (mscorlib.dll) /debug[+|-] Emit debugging information /w[arn]:<level> Set warning level (0-4) /i[mport]:<file> Import specified assembly /out:<file> Specify name of binary output file /codepage:<id> Use the specified code page id to open source files /lcid:<id> Use the specified lcid for messages and default code page /clscompliant[+|-] Specify default for the assembly /versionsafe[+|-] Specify default for members not marked 'override' or 'new'
Easy:
hello.jsprint("Hello, World");jsc /exe hello.jshello.exeJScript.NET uses a colon to specify a type. Types can appear on variable
declarations and in function definitions. The default type is Object,
which can hold any of the other types.
JScript's built-in types include int, long,
float, double, String, Object,
Number, and Boolean. They map to the corresponding .NET
types. JScript also has Array, Function, RegExp,
and Error types that have no direct .NET equivalents.
You can also use any .NET type by importing the appropriate namespace.
Inside ASP+, you use the @import directive. When using the command-line
compiler, you need to use the import statement. If the namespace is not part
of mscorlib, you will also need to tell the compiler to access the assembly
containing the namespace with an option such as jsc /exe /i:path\to\my.dll
mycode.js
You can create arrays using [] after the type name.
You can still use old-style JScript arrays with the Array constructor, but presently the interaction
between "native" arrays (those created with []) and JScript Arrays is not very good. We are working to
improve this!
With the class statement. Inside a class you create fields
and methods just as you would in classic JScript. The default access for
class members is public.
JScript uses function get and function set to
specify properties. You can specify either or both accessors to create read-only,
write-only, or read-write properties. Currently, JScript properties cannot be
parameterised.
Use the extends keyword. JScript can extend any CLS compliant class
You can implement one or more interfaces using the implements keyword, followed
by a comma-separated list of interfaces. Note that you can't declare an interface in JScript.NET, but
you can use any CLS-compliant interface.
The following example shows how to implement IComparable to get a custom sort-order
for an array of objects.
Put the at the start of the declaration. At the moment you have to use
the long form (with ...Attribute at the end) but this requirement
will soon be lifted. The following is a simple Web Service (ASMX) page:
Note that there are no commas or other separators between attributes.
If you just want a generic object to be expando, use the
Object constructor. If you want one of your classes
to be expando, specify the expando attribute