home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

JavaScript: The Definitive Guide

Previous Appendix E Next

E. A Preview of Navigator 4.0

This appendix offers a glimpse at the new JavaScript 1.2 functionality in Navigator 4.0, which is part of the Netscape Communicator suite. This appendix was originally written before any beta version of Communicator were released, and has now been updated in a reprint to reflect the final 4.0 version of Communicator (the JavaScript documentation released with Communicator, however, is itself slightly out of date, and reflects the beta 5 version.) Space constraints in this reprint prevent this appendix from being anything more that a summary of JavaScript 1.2. You can find a more detailed introduction to the features summarized here in an online chapter available from this book's catalog page at http://www.ora.com/catalog/jscript2

E.1 Core Language Features

Navigator 4.0 supports JavaScript version 1.2. In a <SCRIPT> tag, you can specify that this version of the language is to be used by specifying LANGUAGE="JavaScript1.2". There are a number of major changes to the core JavaScript language in this version:

  • JavaScript 1.2 supports a switch statement, a do/while loop, and labelled break and continue statements, just as Java does.

  • The delete operator, which was deprecated in JavaScript 1.1, has been given new life. In JavaScript 1.2, this operator actually deletes or removes properties of an object or top-level variables.

  • The equality operator, ==, behaves slightly differently in JavaScript 1.2. It makes no attempt to convert its operands to the same type, as it did in previous versions of the language, and always returns false if the operands are not of the same type. For backwards compatibility, this new behavior only occurs when JavaScript 1.2 is explicitly being used with a LANGUAGE="JavaScript1.2" attribute in a <SCRIPT> tag.

  • Arrays and objects may be specified as literals in JavaScript 1.2. You specify an array by listing its elements within square brackets, and you specify an object by listing its properties within curly braces. For example:

    o = { name:"Ernest", age:99, male:true };  // a literal object
    a = [1, 2, 4, 8, 16, 32, 64, 128];         // a literal array

  • Function definitions may be nested within other function definitions in JavaScript 1.2. A nested function is only visible within, and may only be invoked from, the function within which it is nested, of course.

  • JavaScript 1.2 supports regular expressions through a new RegExp object and through a new literal syntax. A regular expression is included literally in a program by enclosing it in forward slashes. For example the expression /;+/ represents one or more semicolons. JavaScript 1.2 uses Perl regular expression syntax. The RegExp and String objects have methods that use regular expressions.

  • JavaScript 1.2 features true garbage collection rather than the reference counting model used in Navigator 3.0.

  • There are also a number of miscellaneous changes in JavaScript 1.2. The String object has some new and changed methods. The Array() constructor has slightly different behavior. There have been minor changes to the Number object. For backwards compatibility, these changes typically only take effect when JavaScript 1.2 is explicitly specified with the LANGUAGE attribute of the <SCRIPT> tag.

Previous Home Next
Miscellaneous Differences Book Index Client-side JavaScript

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell