Learn JavaScript In a WeekendAppendix A 1

[cn]Appendix A

[ct]A Brief JavaScript and JScript Object Reference

An object is a construct such as a document, frame, file, folder, or drive that manages its own properties and provides functions known as methods that can be used to control the object or its data.

Both JavaScript and JScript support a wide range of objects. Both provide access to a core set of built-in objects. In addition, other collections of objects are provided by the execution environments in which the two scripting languages operate. The collections of objects supported by JavaScript include:

***Begin Bulleted List***

[bl] Built-in JavaScript objects

[bl] Browser-based objects

[bl] User-defined objects

***End Bulleted List***

The collections of objects supported by JScript include:

***Begin Bulleted List***

[bl] Built-in JScript objects

[bl] Core objects

[bl] Runtime objects

[bl] User-defined objects

***End Bulleted List***

An object’s properties are the attributes of the object and contain stored values that represent some quality of the object (such as the object's name).

Object properties are referenced using the following syntax:

Objectname.property

An object’s methods can be executed in a similar manner using the following syntax:

Objectname.method(p1, p2,...pn)

This appendix provides a quick reference to JavaScript’s built-in core objects as well as major browser-based objects. In addition, JScript’s core and runtime objects are covered as well.

***Begin Note***

Because of the sheer number of properties and methods supported by JavaScript and JScript, there is not enough room in this book to define each of the properties and methods associated with all of the objects defined in this appendix.

More detailed information about these objects and their properties and methods can be found in the text of this book. In addition, you can get detailed information about any JavaScript property or method from This Web page provides links to online copies of Netscape’s JavaScript reference manuals and guides. Similarly, you can get detailed information on every method and property supported by JScript by visiting Microsoft’s scripting Web site at

***End Note***

[1]JavaScript’s Core Objects

JavaScript provides access to a collection of built-in or core objects. These objects provide access to collections of related properties and methods. Table A.1 provides an overview of JavaScript's major core objects and lists their associated properties and methods.

***Begin Table***

Table A.1

Core JavaScript Objects and Their Properties and Methods

ObjectDescription

ArrayProvides for the creation and management of arrays.

Properties: constructor, index, input, length, prototype.

Methods: concat(), join(), pop(), push(), reverse(), shift(), slice(), splice(), sort(), toSource(), toString(), unshift(), valueOf().

BooleanProvides for the creation of a Boolean value.

Properties: constructor, prototype.

Methods: toSource(), toString(), valueOf().

DateProvides access to date and time methods.

Properties: constructor, prototype.

Methods: getDate(), getDay(), getFullYear(), getHours(), getMilliseconds(), getMinutes(), getMonth(), getSeconds(), getTime(), getTimezoneOffset(), getUTCDate(), getUTCDay(), getUTCFullYear(), getUTCHours(), getUTCMilliseconds(), getUTCMinutes(), getUTCMonth(), getUTCSeconds(), getYear(), parse(), setDate(), setFullYear(), setHours(), setMilliseconds(), setMinutes(), setMonth(), setSeconds(), setTime(), setUTCDate(), setUTCFullYear(), setUTCHours(), setUTCMilliseconds(), setUTCMinutes(), setUTCMonth(), setUTCSeconds(), setYear(), toGMTString(), toLocaleString(), toSource(), toString(), toUTCString(), UTC(), ValueOf().

FunctionProvides the capability to create a function.

Properties: arguments, arguments.callee, arguments.caller, arguments.length, arity, constructor, length, prototype.

Methods: apply(), call(), toSource(), toString(), valueOf().

MathProvides access to mathematical functions and constants.

Properties: E, LN10, LN2, LOG10E, LOG2E, PI, SQRT1, SQRT2.

Methods: abs(), acos(), asin(), atan(), ceil(), cos(), exp(), floor(), Log(), Max(), Min(), Pow(), Random(), Round(), Sin(), Sqrt(), Tan().

NumberProvides access to a collection of numeric constants.

Properties: constructor, MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY, prototype.

Methods: toSource(), toString(), valueOf().

RegExpSaves information from regular expressions.

Properties: $1...$9, $, $*, $&, $+, $', $', constructor, global, ignoreCase, input, lastIndex, lastMatch, lastParen, leftContext, multiline, prototype, rightContext, source.

Methods: compile(), exec(), test(), toSource(), toString(), valueOf().

StringProvides the capability to manipulate strings.

Properties: constructor, length, prototype.

Methods: anchor(), big(), blink(), bold(), charAt(), charCodeAt(), concat(), fixed(), fontcolor(), fontsize(), fromCharCode(), indexOf(), italics(), lastIndexOf(), link(), match(), replace(), search(), slice(), small(), split(), strike(), sub(), substr(), substring(), sup(), toLowerCase(), toSource(), toString(), toUpperCase(), valueOf().

***End Table***

[1]JavaScript Browser-Based Objects

When executed inside the browser, JavaScript provides access to a collection of objects that represent the contents of HTML pages. Each of these objects provides access to properties and methods that enable JavaScript to access and manipulate HTML pages and their contents. Table A.2 provides an overview of the major browser-based objects and lists their associated properties and methods.

***Begin Table***

Table A.2

JavaScript Browser-Based Objects and Their Properties and Methods

ObjectDescription

AnchorRepresents a location in a Web page that is the target of a link.

Properties: name, text, x, y.

Methods: N/A.

AreaA type of link object that provides access to an area in an imagemap.

Properties: hash, host, hostname, href, pathname, port, protocol, search, target.

Methods: N/A.

ButtonA representation of a button on a form that has its own methods and properties and that is subject to various events.

Properties: form, name, type, value.

Methods: blur(), click(), focus(), handleEvent().

CheckboxA representation of a check box on a form. The object has its own methods and properties and is subject to various events.

Properties: checked, defaultChecked, form, name, type, value.

Methods: blur(), click(), focus(), handleEvent().

DocumentAn object that provides access to the document that is currently loaded into a browser window and whose properties and methods provide access to viewing and changing the page content.

Properties: alinkColor, anchors, applets, byColor, classes, cookie, domain, embeds, fgColor, formName, forms, height, ids, images, lastModified, layers, linkColor, links, plugins, referrer, tags, title, URL, vlinkColor, width.

Methods: captureEvents(), close(), contextual(), getSelection(), handleEvent(), open(), releaseEvents(), routeEvent(), write(), writeln().

EventAn object that provides access to properties that describe an event.

Properties: data, height, layerX, layerY, modifiers, pageX, pageY, screenX, screenY, target, type, which, width, X, Y.

Methods: N/A.

FileUploadAn object that represents the file upload HTML element.

Properties: form, name, type, value.

Methods: blur(), focus(), handleEvent(), select().

FormAn object created by the HTML <FORM> tag that provides access to all the elements on a form.

Properties: action, elements, encoding, length, method, name, target.

Methods: handleEvent(), reset(), submit().

HiddenA text-based object that is not displayed on a form but that can be accessed programmatically.

Properties: form, name, type, value.

Methods: N/A.

HistoryAn array containing information about all the URLs that have been loaded into the browser window.

Properties: current, length, next, previous.

Methods: back(), forward(), go().

ImageAn object created by the HTML <IMG> tag that provides access to image attributes.

Properties: border, complete, height, hspace, lowsrc, name, src, vspace, width.

Methods: handleEvent().

LayerAn object that represents an HTML layer.

Properties: above, background, bgColor, below, clip.bottom, clip.height, clip.left, clip.right, clip.top, clip.width, document, left, name, pageX, pageY, parentLayer, siblingAbove, siblingBelow, src, top, visibility, window, x, y, zIndex.

Methods: captureEvents(), handleEvent(), load(), moveAbove(), moveBelow(), moveBy(), moveTo(), moveToAbsolute(), releaseEvents(), resizeBy(), resizeTo(), routeEvent().

LinkAn object that represents an HTML hypertext link.

Properties: hash, host, hostname, href, pathname, port, protocol, search, target, text, x, y.

Methods: handleEvent().

LocationAn object that provides access to the window object's location property.

Properties: hash, host, hostname, href, pathname, port, protocol, search.

Methods: reload(), replace().

MimeTypeA predefined JavaScript object that provides access to a specific browser-supported MIME type.

Properties: description, enabledPlugin, suffixes, type.

Methods: N/A.

NavigatorAn object that provides access to the information about the version of Netscape Navigator supported by the browser.

Properties: appCodeName, appName, appVersion, language, mimeTypes, platform, plugins, userAgent.

Methods: javaEnabled(), plugins.refresh(), preference(), savePreferences(), taintEnabled().

ObjectA root object from which all objects are derived.

Properties: constructor, prototype.

Methods: eval(), toSource(), toString(), unwatch(), valueOf(), watch().

OptionAn object created by the HTML <OPTION> tag that provides access to the list of options in a select list.

Properties: defaultSelected, index, length, selected, text, value.

Methods: N/A.

PasswordAn object created by the HTML <INPUT> tag's TYPE="password" option that represents a form's password field.

Properties: defaultValue, form, name, type, value.

Methods: blur(), focus(), handleEvent(), select().

PluginAn object whose properties represent all the browser's plug-ins.

Properties: description, filename, length, name.

Methods: N/A.

RadioA representation of a radio button on a form.

Properties: checked, defaultChecked, form, name, type, value.

Methods: blur(), click(), focus(), handleEvent().

ResetA specialized type of button object that has its own methods and properties.

Properties: form, name, type, value.

Methods: blur(), click(), focus(), handleEvent().

ScreenAn object that contains information about the current screen display.

Properties: availHeight, availLeft, availTop, availWidth.

Methods: N/A.

SelectAn object created by the HTML <SELECT> tag that provides access to a form's select list.

Properties: form, length, name, options, selectedIndex, type.

Methods: blur(), focus(), handleEvent().

StyleAn object that describes the style used by HTML elements and whose properties provide access to specific style attributes.

Properties: align, backgroundColor, backgroundImage, borderBottomWidth, borderColor, borderLeftWidth, borderRightWidth, borderStyle, borderTopWidth, clear, color, display, fontFamily, fontSize, fontStyle, fontWeight, lineHeight, listStyleType, marginBottom, marginLeft, marginRight, marginTop, paddingBottom, paddingLeft, paddingRight, paddingTop, textAlign, textDecoration, textIndent, textTransform,whiteSpace, width.

Methods: borderWidths(), margins(), paddings().

SubmitA specialized type of button object on a form that has its own methods and properties.

Properties: form, name, type, value.

Methods: blur(), click(), focus(), handleEvent().

TextA representation of a single-line text field on a form that has its own methods and properties.

Properties: defaultValue, form, name, type, value.

Methods: blur(), focus(), handleEvent(), select().

TextareaA representation of a multiline text box on a form that has its own methods and properties.

Properties: defaultValue, form, name, type, value.

Methods: blur(), focus(), handleEvent(), select().

WindowAn object that represents a browser window or frame and whose methods can be used to control the window or frame.

Properties: closed, crypto, defaultStatus, document, frames, history, innerHeight, innerWidth, length, location, locationbar, menubar, name, offscreenBuffering, opener, outerHeight, outerWidth, pageXOffset, pageYOffset, parent, personalbar, screenX, screenY, scrollbars, self, status, statusbar, toolbar, top, window.

Methods: alert(), atob(), back(), blur(), btoa(), captureEvents(), clearInterval(), clearTimeout(), close(), confirm(), crypto.random(), crypto.signText(), disableExternalCapture(), find(), focus(), forward(), handleEvent(), home(), moveBy(), moveTo(), open(), print(), prompt(), releaseEvents(), resizeBy(), resizeTo(), routeEvent(), scroll(), scrollBy(), scrollTo(), setHotKeys(), setInterval(), setResizable(), setTimeout(), setZOptions(), stop().

***End Table***

[1]JScript Core Objects

Like JavaScript, JScript provides its own collection of built-in or core objects. Each of these objects provides access to a unique collection of properties and methods. Table A.3 provides an overview of JScript’s core objects and lists their associated properties and methods.

***Begin Table***

Table A.3

Core JScript Objects and Their Properties and Methods

ObjectDescription

ActiveXObjectProvides a reference to an automation object.

Properties:N/A.

Methods: N/A.

ArrayProvides for the creation and management of arrays.

Properties: constructor, length, prototype.

Methods: concat, join, pop, push, reverse, shift, slice, sort, splice, toLocaleString, toString, unshift, valueOf.

ArgumentsRepresents the arguments passed to the currently executing function.

Properties: 0...n, callee, length.

Methods: N/A.

BooleanProvides for the creation of a Boolean value.

Properties: constructor, prototype.

Methods: toString, valueOf.

DateProvides access to date and time methods.

Properties: constructor, prototype.

Methods: getDate, getDay, getFullYear, getHours, getMilliseconds, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getUTCDate, getUTCDay, getUTCFullYear, getUTCHours, getUTCMilliseconds, getUTCMinutes, getUTCMonth, getUTCSeconds, getVarDate, getYear, setDate, setFullYear, setHours, setMilliseconds, setMinutes, setMonth, setSeconds, setTime, setUTCDate, setUTCFullYear, setUTCHours, setUTCMilliseconds, setUTCMinutes, setUTCMonth, setUTCSeconds, setYear, toGMTString, toLocaleString, toUTCString, toString, valueOf, parse, UTC method.

EnumeratorProvides the capability to enumerate a collection of items.

Properties: N/A.

Methods: atEnd, item, moveFirst, moveNext.

ErrorProvides access to script error information.

Properties: description, number.

Methods: N/A.

FunctionProvides the capability to create a function.

Properties: arguments, caller, constructor, prototype.

Methods: toString, valueOf.

GlobalCollects global methods into one object.

Properties: Infinity, NaN.

Methods: escape, eval, isFinite, isNaN, parseFloat, parseInt, unescape.

MathProvides access to mathematical functions and constants.

Properties: E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2,SQRT2.

Methods: abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, min, pow, random, round, sin, sqrt, tan.

NumberProvides access to a collection of numeric constants.

Properties: MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY, constructor, prototype.

Methods: toLocaleString, toString, valueOf.

ObjectProvides the capability to create an instance of any other object type.

Properties: prototype, constructor.

Methods: toLocaleString, toString, valueOf.

RegExpSaves information from regular expressions.

Properties: $1...$9, index, input, lastIndex,lastMatch, lastParen, leftContext, rightContext.

Methods: N/A.

Regular ExpressionStores a regular expression pattern.

Properties: lastIndex, source.

Methods: compile, exec, test.

StringProvides the capability to manipulate strings.

Properties: constructor, length, prototype.

Methods: anchor, big, blink, bold, charAt, charCodeAt, concat, fixed, fontcolor, fontsize, fromCharCode, indexOf, italics, lastIndexOf, link, match, replace, search, slice, small, split, strike, sub, substr, substring, sup, toLowerCase, toUpperCase, toString, valueOf.

VBArrayProvides the capability to use VBScript arrays.

Properties: N/A.

Methods: dimensions, getItem, lbound, toArray, ubound.

***End Table***

[1]JScript Runtime Objects

In addition to its collection of built-in or core objects, JScript also provides access to a collection of runtime objects. These runtime objects, listed in Table A.4, provide access to the computer’s file system.

***Begin Table***

Table A.4

JScript Runtime Objects and Their Properties and Methods

ObjectDescription

DictionaryStores data key, item pairs.

Properties: Count, Item, Key.

Methods: Add (Dictionary), Exists, Items, Keys, Remove, RemoveAll.

DriveProvides access to a disk drive's properties.

Properties: AvailableSpace, DriveLetter, DriveType, FileSystem, FreeSpace, IsReady, Path, RootFolder, SerialNumber, ShareName, TotalSize, VolumeName.

Methods: N/A.

Drives CollectionProvides information about system drives.

Properties: Count, Item.

Methods: N/A.

FileProvides access to a file's properties.

Properties: Attributes, DateCreated, DateLastAccessed, DateLastModified, Drive, Name, ParentFolder, Path, ShortName, ShortPath, Size, Type.

Methods: Copy, Delete, Move, OpenAsTextStream.

Files CollectionProvides access to files contained in a folder.

Properties: Count, Item.

Methods: N/A.

FileSystemObjectProvides access to the entire file system.

Properties: Drives.

Methods: BuildPath, CopyFile, CopyFolder, CreateFolder, CreateTextFile, DeleteFile, DeleteFolder, DriveExists, FileExists, FolderExists, GetAbsolutePathName, GetBaseName, GetDrive, GetDriveName, GetExtensionName, GetFile, GetFileName, GetFolder, GetParentFolderName, GetSpecialFolder, GetTempName, MoveFile, MoveFolder, OpenTextFile.

FolderProvides access to a folder's properties.

Properties: Attributes, DateCreated, DateLastAccessed, DateLastModified, Drive, Files, IsRootFolder, Name, ParentFolder, Path, ShortName, ShortPath, Size, SubFolders, Type.

Methods: Copy, Delete, Move, OpenAsTextStream.

Folders CollectionProvides access to the folders contained within another folder.

Properties: Count, Item.

Methods: Add (Folders).

TextStreamProvides for sequential file access.

Properties: AtEndOfLine, AtEndOfStream, Column, Line.

Methods: Close, Read, ReadAll, ReadLine, Skip, SkipLine, Write, WriteBlankLines, WriteLine.

***End Table***

Error! Unknown switch argument., Error! Unknown switch argument.