What's New in JScript .NET
JScript .NET, the next generation of the Microsoft JScript language, is designed to be a fast and easy way to access the Microsoft .NET platform using the language of the Web. The primary role of JScript .NET is construction of Web sites with ASP.NET and customization of applications with Script for the .NET Framework.
JScript .NET, which is compatible with the ECMAScript standard, has additional features not specified by ECMAScript, such as true compiled code, cross-language support through Common Language Specification (CLS) compliance, and access to the .NET Framework. While the version of JScript .NET included in Visual Studio .NET 2002 leveraged the inherent security of the .NET Framework, JScript .NET 2003 further enhances security by adding a restricted security context for the eval Method.
Several new features in JScript .NET take advantage of the CLS — a set of rules that standardizes such things as data types, how objects are exposed, and how objects interoperate. Any CLS-compliant language can use the classes, objects, and components that you create in JScript .NET. And you, as a JScript developer, can access classes, components, and objects from other CLS-compliant programming languages without considering language-specific differences such as data types. Some of the CLS features that JScript .NET programs use are namespaces, attributes, by-reference parameters, and native arrays.
Following are some of the new features in JScript .NET:
What's New in JScript .NET 2003
- Restricted Security Context for eval Method
- To enhance security, the built-in eval method now by default runs scripts in a restricted security context, regardless of the caller's permissions. Calling eval with "unsafe" as the optional second parameter causes the script to run with the permissions of the caller, which may allow access to the file system, the network, or the user interface. For more information, see eval Method.
What's New in JScript .NET 2002
- Class-based Objects
- JScript .NET (like JScript) supports inheritance through prototype-based objects. JScript .NET also supports class-based objects by allowing you to declare classes that define data and behavior for objects. Classes created in JScript .NET can be used and extended by any .NET language. Classes can inherit the properties and methods of a base class. There are several attributes you can apply to classes and class members that modify their behavior and visibility. For more information, see Class-based Objects.
- JScript Data Types
- In JScript .NET (like JScript), you can write programs without specifying data types for your variables. JScript .NET can also be used as a strongly typed language, in which all variables are bound to a specific data type, or you can use a mix of typed and untyped variables. JScript .NET provides many new data types. You can also use classes and .NET types as data types. For more information, see JScript Data Types.
- Conditional Compilation
- Directives control compilation of your JScript .NET program. The @debug directive, for instance, turns the emission of debugging information on or off for a particular part of your script. For more information, see @debug Directive. The @position directive sets the line number for the debugger for the current line. For more information, see @position Directive. Both of these directives are useful if you are writing code that will be incorporated in other scripts. For more information, see Conditional Compilation.
- JScript Namespaces
- Namespaces prevent naming conflicts by organizing classes, interfaces, and methods into hierarchies. In JScript .NET, you can define your own namespaces. You can also access any .NET Framework namespace with JScript .NET, including ones you define. The package statement enables packaging of related classes for easy deployment and to avoid naming collisions. For more information, see package Statement. The import statement makes a .NET Framework namespace available to a script so that the script can access the classes and interfaces in the namespace. For more information, see import Statement.
- JScript Variables and Constants
- JScript .NET introduces a const statement that defines an identifier that represents a constant value. For more information, see JScript Variables and Constants.
- JScript .NET introduces the enum statement that allows you to construct enumerated data types. With an enumeration, you can specify helpful names for your data type values. For more information, see enum Statement.