Newsreel
Products & Services
Web Watch
Software Update Resource Directory
Events Diary
Articles
The Magazine
Subscribe
Contact Us
Search DNJ Online |

JScript tutorial - part 1
Dino Esposito
covers the history and background behind Microsoft's version of JavaScript
in the first part of his on-line tutorial.
JScript is Microsoft's version of the ECMA 262 standard with some
proprietary extensions, mostly aimed at adding COM support. Unlike
VBScript, which has its origins in Visual Basic, JScript isn't based on
any other language and cannot be considered a stripped-down version of
anything. However, JScript does closely resemble the syntax of C/C++ and
Java.
JScript is Microsoft's response to JavaScript,
which Netscape introduced with version 2.0 of its Netscape Navigator
browser. This allowed Web developers to start writing more responsive and
interactive Web pages by embedding JavaScript code.
The JavaScript name is somewhat misleading as it
has little to do with Java, even though the syntax is quite similar. The
most significant differences, though, are conceptual rather than
technical. Java is a real programming language with a compiler and a
virtual machine. JavaScript, in contrast, is an interpreted language with
a relatively poor arsenal of objects and tools. As a consequence, Java
programs tend to be self-contained, while JavaScript scripts are limited
to putting together existing objects of some hierarchy - for example, the
browser's object model. Perhaps due to this misleading similarity, though,
JavaScript has gained a wide acceptance among the Web community.
Microsoft responded by providing Internet
Explorer 3.0 with cutting-edge scripting capabilities. IE 3.0 had an open
architecture called ActiveX Scripting (recently renamed to Windows
Script). By defining a COM programming interface for parsers, Microsoft
made its browser scripting language agnostic. Internet Explorer was
capable of supporting any scripting language for which there was a parser
module compatible with the ActiveX Scripting specification. Since
Microsoft was already promoting Visual Basic, choosing a cut-down version
as the favoured scripting language was quite a natural choice. Thus,
VBScript came to life.
However, since Internet Explorer had such a
flexible architecture, it was also possible to write a parser for
JavaScript. In the process, Microsoft developers decided to add some extra
features to JavaScript, known as extensions. Since no standard was then
foreseeable this didn't appear to present any problems. Microsoft went for
a brand new name for its version of the language - JScript.
JScript versus JavaScript
For about two years in the mid 1990s, we witnessed a sort of bloodless
war between JavaScript and Jscript and the products hosting them - the
browsers and Web servers. As soon as users attempted to standardise on one
vendor's version, the competitor released an update invalidating most of
the effort. It was late in 1997 when Netscape, Microsoft and other
companies finally agreed on a vendor-neutral standard called ECMAScript,
as defined by the European Computer Manufacturers Association.
However, having a standard on paper is not the
same as having a working and compliant language implementation of it. For
instance, JScript 3.0, which shipped with Internet Explorer 4.0, was
declared ECMA-compliant while Netscape Communicator 4.0 supported
JavaScript 1.2, which was only partially compatible with ECMA. The ECMA
standard, in fact, was based mainly on JavaScript 1.1.
Today there are versions of JScript and
JavaScript which are certainly incompatible. In practice, though,
differences in the Document Object Model between browsers are more
significant than the differences between the scripting languages used.
What's ECMA-compliant in Jscript?
Today, version 5.1 of VBScript and JScript are available from the
Microsoft scripting Web site at http://msdn.microsoft.com/scripting.
Version 5.5 is already in beta, available from the same Web site. Not all
the features these versions provide are compatible with the latest ECMA
standard. In particular, be aware that the following language features
that you may use frequently aren't actually part of the ECMA 1.0 standard
and successive modifications:
- The 'switch' statement
- Regular expressions
- String functions which add Web-oriented features
- Functions to manipulate strings
- All the COM related features
All the rest of JScript can be safely used since it's actually part of
the standard. Functions like anchor(), link() and italics() haven't been
mentioned in the specification for a simple reason: to keep the language
as independent as possible from the Web, since an ECMA language may be
employed in any programming context. The 'switch' statement, as well as
some other string functions such as replace() and match(), have been left
out for the sake of simplicity.
The lack of COM support in the ECMA standard
comes as no surprise. COM is a Microsoft technology, despite successful
ports to platforms other than Windows. COM adds unprecedented power to
your scripts but can also make them less portable.
Remote scripting is a script-based technology to
issue calls to remote ECMA objects. To make it work with as many browsers
as possible, Microsoft implemented the underlying engine to comply with
the ECMAScript standard. Consequently, though, you cannot serialise
recordset objects from the server to the client, because the
transportation layer doesn't know how to handle them. Recordsets are, in
fact, COM objects!
When ECMA is Really Important
While ECMA is an important milestone, you don't have to regard
Microsoft's extensions as un-useable and to be avoided. You do need to be
aware of what you can expect browsers, other than IE, to support. If you
use COM extensively within an HTML page, you may experience problems with
non-Microsoft browsers. If you use the standard ECMA objects you'll be
safe whatever browser your clients utilise. However, it's best to think of
JScript as a language per se, not just for the Web. If you plan to use
JScript within Windows you can feel free to get the most out of it and to
exploit all its features to the fullest.
ECMA Edition 3.0
JScript is a superset of ECMAScript. Indeed you can also use the
keyword ecmascript within the <SCRIPT> tag and have Internet
Explorer recognise it as a synonym of JScript. Sadly, though, this doesn't
automatically disable non-ECMA features in JScript.
Edition 3.0 of the ECMA standard is now ready for
release. It should extend the specification to cover most of the features
that Microsoft and Netscape have introduced since version 2.0 was
introduced in April 98. Notably, the additions in ECMA 3.0 include the
'switch' statement, regular expressions, exception handling, plus some
formatting functions. Basically, the ECMA group has been working to make
all the current features implemented by Microsoft and Netscape browsers
the new standard!
So will ECMA 3.0 remove, at least in the short
term, any differences between the browsers? According to Andrew Clinick,
program manager in the Microsoft Script Technology group, and member of
the ECMA committee: "In the short term, there will be some minor
incompatibilities with the Edition 3.0 specification and JScript 5.0,
since JScript was released before the standard was completed. We are
working on a newer version of JScript that will be 100 percent ECMAScript
compatible, so the next release should return us to full ECMAScript
compatibility." See Andrews article "Adventures in
Scripting" at http://msdn.microsoft.com/voices/scripting.asp
for more details.
Microsoft is about to ship JScript 5.5 (see http://msdn.microsoft.com/scripting)
which will be totally compliant with ECMA 3.0. Meanwhile, ECMA 4.0 is
already being worked on.
Top of the page
Articles index
< JScript Tutorial -- Next
>
Copyright © 2001 Matt Publishing Limited. All
rights reserved. No part of this site may be reproduced without the prior
consent of the copyright holder.
|
Part 1: History and background
Part 2: Variables, types and operators
Part 3: Arrays
Part 4: Strings
Part 5: Objects, constructors and protypes
Part 6: Remote scripting
Part 7: Accessing COM objects
Part 8: Error handling
Part 9: Runtime code evaluation
Part 10: Expando properties
Part 11: JScript.NET
Part 12: Conditional compilation |