JScript
From Wikipedia, the free encyclopedia
JScript | |
---|---|
Appeared in | 1996 |
Developer | Microsoft |
Latest release | 5.7/ November 2006 |
Typing discipline | dynamic, weak, duck |
Major implementations | Windows Script, JScript .NET |
Influenced by | Javascript, ECMAScript |
OS | Microsoft Windows |
Website | JScript |
JScript is the Microsoft dialect of the ECMAScript scripting programming language specification.
JavaScript (the Netscape/Mozilla implementation of the ECMA specification), JScript, and ECMAScript are very similar languages. In fact the name "JavaScript" is often used to refer to ECMAScript or JScript.
JavaScript is used on web pages for scripting, although it can be and is also used in other embedding scenarios.
- For general information about the language, its history, and uses see the JavaScript article. The article on ECMAScript has information on various dialects and implementations of ECMAScript and the history of the specification. JavaScript syntax is described in its own article. The rest of this article focuses on Microsoft implementation.
JScript is implemented as a Windows Script engine. This means that it can be "plugged in" to any application that supports Windows Script, such as Internet Explorer, Active Server Pages, and Windows Script Host. It also means that any application supporting Windows Script can use multiple languages — JScript, VBScript, Perl, and others. JScript was first supported in Internet Explorer 3.0 browser released in August 1996. As with any other Active Scripting engine, it is available through Internet Explorer, Windows Script Host, and Active Server Pages. The typical file extension of JScript source code files is .js.
The most recent version of JScript is JScript .NET, which is based on the yet-unfinished edition 4 of the ECMAScript standard, and can be compiled for the Microsoft .NET platform. JScript.NET adds several new features to ECMAScript ed. 3, such as optional static type annotations.
Contents |
[edit] Versions
[edit] JScript
The original JScript is an Active Scripting engine. Like other Active Scripting languages, it is built on the COM/OLE Automation platform and provides scripting capabilities to host applications. This is the version used when hosting JScript inside a Web page displayed by Internet Explorer, in an HTML application, in classic ASP, in Windows Script Host scripts and several other Automation environments. JScript is sometimes referred to as "classic JScript" or "Active Scripting JScript" to differentiate it from newer .NET-based versions.
Version | Date | Introduced with[1] | Based on1 | Approx. JavaScript |
---|---|---|---|---|
1.0 | Aug 1996 | Internet Explorer 3.0 | Netscape JavaScript | 1.0 |
2.0 | Jan 1997 | Windows IIS 3.0 | Netscape JavaScript | 1.1 |
3.0 | Oct 1997 | Internet Explorer 4.0 | ECMA-262 1st edition2 | 1.3 |
4.0 | Visual Studio 6.0 (as part of Visual InterDev) | ECMA-262 1st edition | 1.3 | |
5.0 | Mar 1999 | Internet Explorer 5.0 | ECMA-262 2nd edition | 1.4 |
5.1 | Internet Explorer 5.01 | ECMA-262 2nd edition | 1.4 | |
5.5 | Jul 2000 | Internet Explorer 5.5 & Windows CE 4.2 | ECMA-262 3rd edition | 1.5 |
5.6 | Oct 2001 | Internet Explorer 6.0 & Windows CE 5.0 | ECMA-262 3rd edition | 1.5 |
5.7 | Nov 2006 | Internet Explorer 7.0 | ECMA-262 3rd edition + ECMA-327 (ES-CP)3 | 1.5 |
Note (1): JScript supports various features not specified in the ECMA standard[2], as does JavaScript.
Note (2): JScript 3.0 is "the first scripting language to fully conform to the ECMA-262 standard" (Source: Microsoft PressPass)
Note (3): JScript 5.7 includes an implementation of the ECMAScript Compact Profile (ECMA-327) which turns off features not required by the ES-CP when using the "JScript.Compact" ProgID.
JScript is also available on Windows CE (included in Windows Mobile, optional in Windows Embedded CE). The Windows CE version lacks Active Debugging.
(Source: MSDN, WebmasterWorld Forum)
[edit] Managed JScript
Managed JScript is an implementation of JScript for the Dynamic Language Runtime, it is part of Microsoft's dynamic languages for .NET along with IronRuby, IronPython, and Dynamic Visual Basic. Unlike JScript .NET which is less dynamic than the original JScript but provides CLS compatibility, Managed JScript is designed on top of the DLR and provides the features needed for scripting scenarios.
While it is primarily designed to be used within Silverlight and ASP.NET at this time, it can also easily be embedded within any .NET application.
(Source: JScript Blog, Jim Hugunin's Thinking Dynamic blog, Source: Blog of Jitu)
Two builds of Managed JScript exists, one for the Desktop CLR and one for the CoreCLR (Microsoft Silverlight)
Version | Platform | Date | Introduced with | Based on |
---|---|---|---|---|
1.0.0.0 | Desktop CLR 2.0 | 2007 | ASP.NET Futures (July 2007 preview) | ECMA-262 3rd edition |
1.1.20625.0 | CoreCLR 1.1 | 2007 | Microsoft Silverlight 1.1 Alpha (Sep 2007 refresh) | ECMA-262 3rd edition |
Managed JScript is not supported in the .NET Compact Framework.
(Source: files versions of Microsoft.JScript.Runtime.dll in ASP.NET Futures and Silverlight 1.1 folders)
[edit] JScript .NET
JScript .NET is a Microsoft .NET implementation of JScript, it is a CLS language and thus inherit very powerful features, but lacks many features of the original JScript language, making it inappropriate for many scripting scenarios. JScript .NET can be used for ASP.NET pages and for complete .NET applications, but the lack of support for this language in Microsoft Visual Studio place it more as an upgrade path for classic ASP using classic JScript than as a new first-class language.
Version | Platform | Date | Introduced with | Based on |
---|---|---|---|---|
7.0 | Desktop CLR 1.0 | 2002-01-05 | Microsoft .NET Framework 1.0 | ECMA-262 3rd edition4 |
7.1 | Desktop CLR 1.1 | 2003-04-01 | Microsoft .NET Framework 1.1 | ECMA-262 3rd edition4 |
8.0 | Desktop CLR 2.0 | 2005-11-07 | Microsoft .NET Framework 2.0 | ECMA-262 3rd edition4 |
Note (4): JScript .NET is "being developed in conjunction with ECMAScript Edition 4" (Source: MSDN)
JScript .NET is not supported in the .NET Compact Framework.
Note JScript .NET versions are not related to classic JScript versions. JScript .NET is a separate product. Even though JScript .NET is not supported within the Visual Studio IDE, its versions are in sync with other .NET languages versions (C#, VB.NET, VC++) that follows their corresponding Visual Studio versions.
.NET Framework 3.0 and 3.5 are built on top of 2.0 and do not include newer releases of JScript .NET.
(Source: file version of Microsoft.JScript.dll in each framework install)
[edit] Samples
Classic JScript can be used in many applications. Most common uses are client-side script in Internet Explorer and administrative scripts using the Windows Script Host (WSH, aka WScript). Because the application hosting JScript adds its own objects, functions and properties, the language has a limited set of built-in features and any real use depends on the hosting application. Managed JScript follows the same idea, and the hosting application adds objects to the engine.
[edit] JScript in Windows Script Host
This sample shows how JScript uses COM/OLE Automation objects and enumerations, and how the WScript object, which is part of the Windows Script Host, is made available to JScript. It can be simply saved as a .js script file and executed as it (it is associated with WScript.exe for GUI mode, or CScript.exe for CLI mode).
var fso = new ActiveXObject("Scripting.FileSystemObject"); var fldr = fso.getFolder("C:\\Windows"); var msg = new Array(); msg.push("Files in \""+ fldr.path +"\" :\r\n\r\n") var ef = new Enumerator(fldr.files); for( ef.moveFirst(); !ef.atEnd(); ef.moveNext() ) msg.push(ef.item().name +"\r\n"); WScript.echo(msg.join(""));
[edit] JScript in Internet Explorer
This client-side sample shows how classic JScript works within Internet Explorer to execute script embedded in or linked from Web pages. Just like WSH makes the WScript object available to JScript, Internet Explorer makes the window object available to JScript, and makes all window members global members (document object, alert function, …).
<html> <head> <script language="JScript"> function init() { var el = document.getElementById("dhtmlspan"); el.innerHTML = "Executed when done loading page."; } </script> </head> <body onload="init()"> <p> <script language="JScript"> document.write("Executed during load."); </script> </p> <p> <span id="dhtmlspan">Please wait…</span> </p> </body> </html>
[edit] JScript in Active Server Pages
ASP is an extension to IIS to run server-side Active Scripting code. Blocks between <% and %> are parsed and executed on the server, as well as standard script blocks with the runat argument set to "server". The ASP framework provides Request, Response and Server objects to the script engine to allow code to inject data in the response sent to the client and to retrieve data from the request (form, querystring, posted data).
<%@ language="JScript"%> <html> <body> <% Response.write("Executed server-side when generating the response.<br/>"); %> <script language="JScript" runat="server"> Response.write("Executed last<br/>"); </script> <%= "The = prefix is identical to Response.write.<br/>" %> </body> </html>
[edit] JScript .NET
JScript .NET is a compiled language. It generates CIL binaries for stand-alone console and windows applications, libraries, or ASP.NET programs. The command-line compiler is included in the .NET Framework.
import System; var _name; Console.WriteLine("Hello, what's your name?"); Console.WriteLine("Type your name: "); var _name = Console.ReadLine(); //provide a number and it will output it below, without error Console.WriteLine("Hello, " + _name);
You can compile this file using JSC to generate a .exe file: jsc sample.js
.
JScript .NET can be used server-side for Web applications with the ASP.NET framework. Visual Studio usually generate code-behind, but inline code, similar to classic ASP, will get compiled to CIL and then executed on the fly.
<%@ Page Language="JScript"%> <html> <body> <% Response.Write("Compiled on the fly and executed server-side.<br/>"); %> </body> </html>
While the @ directive seems to imply classic JScript, ASP.NET pages (.aspx) never uses Active Scripting engines. It will try to load a .NET CLR language and this page will be processed by the JScript .NET compiler.
[edit] Managed JScript in ASP.NET
Managed JScript can be used server-side with ASP.NET with the DLR extensions. This is currently only available with the ASP.NET Futures preview.
<%@ Page Language="ManagedJScript"%> <html> <body> <% Response.Write("Executed on the fly server-side.<br/>"); %> </body> </html>
To be able to execute this on .NET 2.0, the DLR framework and Managed JScript references must be included in the Web.config assemblies references.
[edit] Differences from JavaScript
Please help improve this section by expanding it. Further information might be found on the talk page or at requests for expansion. |
JScript supports Conditional comment, but JavaScript does not.
In addition to other internal implementation differences, JScript uses non-generational mark-and-sweep garbage collection[3] whereas JavaScript (the original implementation of which is the SpiderMonkey engine) uses a generational mark-and-sweep system.
[edit] See also
- Hello World program in JScript
- JavaScript, Originally LiveScript, it was the first implementation of this language family
- ECMAScript, the ECMA language definition standard which all implementations must at a minimum follow
- VBScript
- iMacros
- JScript.NET
- Active Scripting
- Windows Script File
- Windows Script Host
[edit] References
- ^ Microsoft Developer Network. Version Information (JScript 5.6). Retrieved on 2007-08-12.
- ^ Microsoft Developer Network. Microsoft JScript Features - Non-ECMA (JScript 5.6). Retrieved on 2007-08-12.
- ^ Eric Lippert. How Do The Script Garbage Collectors Work?. Retrieved on 2007-08-12.
[edit] External links
- classic JScript documentation in the MSDN Library
- JScript 5.7 Release Notes
- JScript .NET documentation in the MSDN Library
- JScript blog
[edit] JScript downloads
The latest versions of classic JScript (5.6 and 5.7) are bundled with Internet Explorer, so it is already installed and up to date on many Windows computers. For people using another browser and not installing Internet Explorer updates the JScript engine is also available as part of the Windows Script package, which is the set of scripting components of Windows (containing VBScript, JScript, Windows Script Host, Windows Script Component and Windows Script Runtime).
- Windows Script 5.7 for Windows 2000, including JScript 5.7
- Windows Script 5.7 for Windows XP, including JScript 5.7
- Windows Script 5.7 for Windows Server 2003, including JScript 5.7
The latest version for Windows 98, Me and NT4 is Windows Script 5.6, which used to be available on Microsoft Download Center but seems to have been removed when 5.7 went online. Windows Vista already contains Windows Script 5.7.
[edit] JScript .NET downloads
The latest version of JScript .NET is bundled with the .NET Framework 2.0.
- .NET Framework 2.0 for x86, including JScript .NET 8.0
- .NET Framework 2.0 for x64, including JScript .NET 8.0
- .NET Framework 2.0 for IA64, including JScript .NET 8.0
[edit] Managed JScript downloads
Managed JScript isn't final yet, but preview versions are bundled with Silverlight 1.1 preview and ASP.NET Futures preview.
- ASP.NET Futures preview, including Managed JScript 1.0 for Desktop CLR
- Silverlight 1.1 preview, including Managed JScript 1.1 for CoreCLR
|
|
|