Server-Side Javascript 1.2 Reference
Total Page:16
File Type:pdf, Size:1020Kb
World Wide Web security URLmerchant systemChat community system server navigator TCP/IP HTML Publishing PersonalServer-Side JavaScript Reference Inter ww Version 1.2 Proxy SSL Mozilla IStore Publishing Internet secure sockets layer mail encryption HTMLhttp://www comp.syselectronic commerce JavaScript directory server news certificate Proxy Netscape Communications Corporation ("Netscape") and its licensors retain all ownership rights to the software programs offered by Netscape (referred to herein as "Software") and related documentation. Use of the Software and related documentation is governed by the license agreement accompanying the Software and applicable copyright law. Your right to copy this documentation is limited by copyright law. Making unauthorized copies, adaptations, or compilation works is prohibited and constitutes a punishable violation of the law. Netscape may revise this documentation from time to time without notice. THIS DOCUMENTATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL NETSCAPE BE LIABLE FOR INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY KIND ARISING FROM ANY ERROR IN THIS DOCUMENTATION, INCLUDING WITHOUT LIMITATION ANY LOSS OR INTERRUPTION OF BUSINESS, PROFITS, USE, OR DATA. The Software and documentation are copyright ©1994-1998 Netscape Communications Corporation. All rights reserved. Netscape, Netscape Navigator, Netscape Certificate Server, Netscape DevEdge, Netscape FastTrack Server, Netscape ONE, SuiteSpot and the Netscape N and Ship’s Wheel logos are registered trademarks of Netscape Communications Corporation in the United States and other countries. Other Netscape logos, product names, and service names are also trademarks of Netscape Communications Corporation, which may be registered in other countries. JavaScript is a trademark of Sun Microsystems, Inc. used under license for technology invented and implemented by Netscape Communications Corporation. Other product and brand names are trademarks of their respective owners. The downloading, exporting, or reexporting of Netscape software or any underlying information or technology must be in full compliance with all United States and other applicable laws and regulations. Any provision of Netscape software or documentation to the U.S. Government is with restricted rights as described in the license agreement accompanying Netscape software. Recycled and Recyclable Paper Version 1.2 ©1998 Netscape Communications Corporation. All Rights Reserved Printed in the United States of America. 00 99 98 5 4 3 2 1 Netscape Communications Corporation, 501 East Middlefield Road, Mountain View, CA 94043 New Features in this Release JavaScript version 1.2 provides the following new features and enhancements: • Changes to the Array object. • Array objects can be created using literal notation. • When the <SCRIPT> tag includes LANGUAGE="JavaScript1.2", array(1) creates a new array with a[0]=1. • When created as the result of a match between a regular expression and a string, arrays have new properties that provide information about the match. • concat joins two arrays and returns a new array. • pop removes the last element from an array and returns that element. • push adds one or more elements to the end of an array and returns that last element added. • shift removes the first element from an array and returns that element • unshift adds one or more elements to the front of an array and returns the new length of the array. • slice extracts a section from an array and returns a new array • splice adds and/or removes elements from an array and returns the removed elements. • sort now works on all platforms. It no longer converts undefined elements to null; instead, it sorts them to the high end of the array. 3 • Changes to the Function object. • Nested functions. You can nest functions within functions. (That is, JavaScript now supports lambda expressions and lexical closures.) See Function. • New function property arity. The arity property indicates the number of arguments expected by a function. • New arguments property. The arguments.callee property provides information about the invoked function. • New Lock class. The Lock class allows safe sharing of information with multiple incoming requests. • Changes to the Number object. Number now produces NaN rather than an error if x is a string that does not contain a well-formed numeric literal. • New RegExp object for regular expressions. Regular expressions are patterns used to match character combinations in strings. You create a regular expression as an object that has methods used to execute a match against a string. You can also pass the regular expression as an argument to the String methods match, replace, search, and split. The RegExp object has properties most of which are set when a match is successful, such as lastMatch which specifies the last successful match. The Array object has new properties that provide information about a successful match such as input which specifies the original input string against which the match was executed. See RegExp for information. • New SendMail class. The SendMail class lets you generate email from JavaScript. • New or changed String methods. • charCodeAt returns a number specifying the ISO-Latin-1 codeset value of the character at the specified index in a string object. • concat combines the text of two strings and returns a new string. • fromCharCode constructs a string from a specified sequence of numbers that are ISO-Latin-1 codeset values. • match executes a search for a match between a string and a regular expression. 4 Server-Side JavaScript Reference • replace executes a search for a match between a string and a regular expression, and replaces the matched substring with a new substring. • search tests for a match between a string and a regular expression. • slice extracts a section of an string and returns a new string. • split includes several new features and changes. It can take a regular expression argument, as well as a fixed string, by which to split the object string. It can take a limit count so that it won't include trailing empty elements in the resulting array. If you specify LANGUAGE="JavaScript1.2" in the <SCRIPT> tag, string.split(" ") splits on any run of one or more white space characters including spaces, tabs, line feeds, and carriage returns. • substr returns the characters in a string collecting the specified number of characters beginning with a specified location in the string. • substring if you specify LANGUAGE="JavaScript1.2" in the <SCRIPT> tag, this method no longer swaps index numbers when the first index is greater than the second. • New top-level functions Number and String. The Number function converts an object to a number. The String function converts an object to a string. • Changes to methods of all objects. • eval is no longer a method of individual objects; it is available only as a top-level function. • toString converts an object or array to a literal. For this behavior, LANGUAGE="JavaScript1.2" must be specified in the <SCRIPT> tag. • watch is a new method of all objects. It watches for a property to be assigned a value and runs a function when that occurs. • unwatch is a new method of all objects. It removes a watchpoint set with the watch method. 5 • New or changed operators. • The new delete operator deletes an object, an object’s property, or an element at a specified index in an array. See “delete” on page 395. •If the <SCRIPT> tag uses LANGUAGE=JavaScript1.2, the equality operators == and != do not attempt to convert operands from one type to another, and always compare identity of like-typed operands. See “Comparison Operators” on page 385. • New or changed statements. • The break and continue statements can now be used with the new labeled statement. • do...while repeats a loop until the test condition evaluates to false. • export allows a signed script to provide functions to other signed or unsigned scripts. • import allows a script to import functions from a signed script which has exported the information. • label allows the program to break outside nested loops or to continue a loop outside the current loop. • switch allows the program to test several conditions easily. See the Server-Side JavaScript Guide for information on additional features. 6 Server-Side JavaScript Reference Contents New Features in this Release .......................................................................3 About this Book ..............................................................................................13 New Features in this Release ..............................................................................13 What You Should Already Know .......................................................................13 JavaScript Versions ..............................................................................................14 Where to Find JavaScript Information ................................................................15 Document Conventions .......................................................................................16 Part 1 Object Reference Chapter 1 Objects, Methods, and Properties ......................................21 Array .....................................................................................................................22 blob ......................................................................................................................43 Boolean ................................................................................................................48