, or tag. Use of this tag is highly deprecated but it still persists in some legacy content. See also:
Element object, KBD object, PRE object
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onClick
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onDblClick
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onDragStart
-
3.0 +
-
4.0 +
-
-
-
-
onFilterChange
-
3.0 +
-
4.0 +
-
-
-
-
onHelp
-
3.0 +
-
4.0 +
-
-
-
Warning
onKeyDown
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onKeyPress
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onKeyUp
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseDown
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseMove
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseOut
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseOver
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseUp
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onSelectStart
-
3.0 +
-
4.0 +
-
-
-
-
Inheritance chain: Element object, Node object
Literal (Definition) Constant values used to initialize or assign a value. Literals are constant values used in assignments or as arguments to functions or expressions. A literal is considered to be a primary expression when it is being evaluated. There are several kinds of literals. They are all based on the primitive types. The ECMA standard defines four basic data types, which should be sufficient for most purposes; however, a hosted interpreter may provide other more esoteric primitive values. Here are the four core standard types: ❑
Null
❑
Boolean
❑
Numeric
❑
String
1349
JavaScript Programmer's Reference
These are objects that can also be manufactured from literals: ❑
Array
❑
Date
❑
Regular expression
❑
Object
❑
Void
String literals also include escaped character literals which may also be used in regular expressions. Host environments additionally define others for special purposes depending on the implementation. See also:
Boolean literal, Character constant, Constant, Lexical element, Null literal, Numeric literal, Primary expression, String literal, Token
Cross-references: ECMA 262 edition 2 – section – 7.7 ECMA 262 edition 2 – section – 11.1.3 ECMA 262 edition 3 – section – 7.8 ECMA 262 edition 3 – section – 11.1.3 O'Reilly JavaScript Definitive Guide – page – 30
Little endian (Definition) A bit ordering standard for some CPU models.
1
2
4
8
16
Increasing bit value
See also:
1350
byte
32
64
128
L – LiveConnect (Product)
LiveConnect (Product) A Netscape Communications technology that provides a means of communicating between plugins and Java applets. In Netscape, communication between scripts and Java applets takes place via the LiveConnect interface. LiveConnect was originally designed for just this purpose. LiveConnect is only implemented in Netscape. However, similar but not identical functionality is available in MSIE via the ActiveX interface. LiveConnect is most effective if you can also understand the internals of Java applets and can program in Java yourself. You can use LiveConnect to gain read and write access to the public fields of an applet and you can also invoke public methods. You can also interact with standard Java system classes that are built into the Netscape browser. If a plugin is Java-enabled, then in Netscape you can interact with that plugin in the same way. From the opposite direction, applets and Java-enabled plugins can invoke JavaScript functions and can read and write JavaScript object properties. The Real Video plugin uses this to great effect as do many other media plugins. LiveConnect is constructed around some built-in objects that encapsulate various Java classes and objects. These are: ❑
JavaObject – An encapsulation of an instance of a Java object that belongs to a JavaClass
❑
JavaClass – An encapsulation of a Java class for access to static properties and methods
❑
JavaPackage – A collection of JavaClass and JavaPackage objects in a tree-like hierarchy
With these encapsulations, you can operate on Java objects as if they were JavaScript objects. That is necessary because although you can generally convert between primitive types, the object types are too dissimilar to convert properly. There are some interesting opportunities here for extending the capabilities of your scripts with the facilities offered by Java. However, the downside is that you need to have a VM running. Netscape supports its own internal VM at least up to version 4, but the trend is for browsers to use the OS hosted VM and to not provide any embedded Java execution context. This may provide additional benefits such as sharing Java classes amongst several applications and shortening the start-up time since the VM could be expected to be running already. LiveConnect becomes particularly useful when accessing the java.lang.System class from scripts running in Netscape. In MSIE, you could create a special applet that then gained access to the system class for you. Using this capability to any useful extent starts to impinge on the security model and requires that trusted scripts are used. This is usually enough to deter most people from exploring it more deeply. However, if you can gain that trust, by using signed scripts, you may then be able to access the Java IO facilities and read/write files. Working the other way, LiveConnect provides a way for Java code to execute a string as JavaScript. This is very like an eval() call from the native JavaScript environment.
1351
JavaScript Programmer's Reference
Warnings: ❑
❑
Be careful not to confuse the following: ❑
LiveWire
❑
LiveScript
❑
LiveConnect
In Netscape version 3, a bug in the conversion routines yielded all Java primitives as JavaScript objects instead of JavaScript primitives. This causes a few problems because Number and Boolean objects in JavaScript behave slightly differently to the primitive representations, mostly to do with operator overloading and precedence. Objects will prefer to concatenate as strings rather than add as numbers for example. The valueOf() method will provide a way to work around this. See also:
ActiveX, Glue code, Java calling JavaScript, Java method calls, Java method data conversion, Java to JavaScript values, JavaScript to Java values, LiveScript, Plugin events, Plugin.isActive()
LiveScript (Product) This was the original name for JavaScript when it was first introduced by Netscape Communications. Maybe LiveScript wouldn't have caught on and become so popular, but now people routinely confuse it with Java. Even more so now that interpreters for JavaScript are available written in Java and some server-side application tools allow you to write Java code but run it in a script interpreter. That would be Java script not JavaScript.
Warnings: ❑
Be careful not to confuse the following: ❑
LiveScript
❑
LiveWire
❑
LiveConnect
❑
LiveWire is the former name for Server-Side Javascript.
❑
LiveConnect is a mechanism for allowing JavaScript to talk to Java in a Netscape browser. See also:
JavaScript language, JavaScript version, LiveConnect, LiveWire
livescript: URL (Request method) This is a pseudonym for the javascript: URL. See also:
1352
URL, javascript: URL
L – LiveWire (Product)
LiveWire (Product) Netscape Communications' server-side JavaScript compiler. This was the original name for JavaScript when used in the server. Now it is simply called ServerSide JavaScript. Sometimes SSJS for short. The LiveWire JavaScript interpreter is used in Netscape Enterprise Server. In this environment you can also compile the JavaScript code which further blurs the distinction between Java and JavaScript.
Warnings: ❑
Be careful not to confuse the following: ❑
LiveWire
❑
LiveScript
❑
LiveConnect
See also:
LiveScript, Server-side JavaScript
Local time (Definition) The locale specific time value. Availability:
ECMAScript edition – 2
Local time is the calendar time for the current locale. Local time and UTC time differ by an amount derived by adding the Local Time Zone Adjustment and the Daylight Savings Time Adjustment together. Adding these to the UTC time gives the local time. Conversion of UTC time (ut)to local time is defined by: LocalTime(t) = ut + LocalTZA + DaylightSavingTA(ut)
Conversion from local time (lt)to UTC is defined by: UTC(lt) = lt – LocalTZA – DaylightSavingTA(lt – LocalTZA)
The following expression may not always test true: t = UTC(LocalTime(t))
1353
JavaScript Programmer's Reference
Converting from UTC to local time and back may not yield an identical value due to deficiencies in daylight savings time computations. ECMA does not mandate that a compliant implementation needs to take DST into account only that it be aware that DST may be in force. Some locales use the same DST setting all year round in some years and that is difficult to predict and encapsulate into an algorithm. See also:
Broken down time, Calendar time, Date and time, Daylight savings time adjustment, Local time zone adjustment
Cross-references: ECMA 262 edition 2 – section – 15.9.1.9 ECMA 262 edition 3 – section – 15.9.1.9
Local time zone adjustment (Definition) An adjustment to locale specific time. Availability:
ECMAScript edition – 2
ECMA compliant implementations are expected to determine the local time zone adjustment. The local time zone adjustment is a value (internally referred to as LocalTZA) which is measured in milliseconds and can be added to the UTC value representing the local standard time. The ECMA standard states that daylight savings time is not reflected in the LocalTZA value. LocalTZA does not vary with time but depends only on the geographic location. See also:
Broken down time, Daylight savings time adjustment, Local time
Cross-references: ECMA 262 edition 2 – section – 15.9.1.7 ECMA 262 edition 3 – section – 15.9.1.7
Locale-specific behavior (Definition) Behavior that depends on a locale setting. The locale setting is a way of defining how programs operate in an international or geographic context. Running software in London and New York may be very similar apart from the instantaneous time setting. The time in New York is 5 hours behind London. If the software running in both locations needs to communicate with the other and will have to perform time based operations on data, then to remain properly synchronized they may need to be aware of the number of time zones between the two systems and make adjustments accordingly.
1354
L – Localization (Definition)
Other behavior may dictate date formats, currency symbols, the format of decimal values, thousands separators and spelling. Non English speaking locales may use the same textual presentation (Roman Scripting) but spell words in the local language. Character set substitution may accomplish much of what's required although this is somewhat ameliorated by the use of Unicode. Sometimes the direction that the text flows may be different. For example, European, Middle-Eastern and Asian languages use different character alphabets and text directions. The implementors should thoroughly document all of this locale specific behavior. See also:
Behavior, Broken down time, Character set, Character-case mapping, Unicode
Localization (Definition) The process by which geographic, international and regional differences are managed. JavaScript is used all over the world in a wide variety of environments, platforms and contexts. Portability issues arise when moving between platforms. They are also present when relocating a platform geographically. At the very least a time setting will need to change, and to record an event in a coordinated time framework, the offset from that known time reference needs to be known. There will be cultural, language and currency changes necessary as well as number formatting rule variations that need to be taken account of. Indeed the differences in some locales may completely change the native alphabet that the user is prepared to work with. Even the direction of the text flow may change in extreme circumstances. Moving around Europe certainly requires that different accented symbols be used in each country. Fortunately the Unicode standard covers a great many of these national variants. Even so, JavaScript is fundamentally based on the American English language and even with the international support of the Unicode character set, the structural layout of the script source text may still conform to the underlying English language form. Even so there are issues with the spelling of words such as Color. Typically, a localized implementation may allow the use of accented and national characters in identifier names but would still retain the English spelled keywords and punctuation characters. As well as character sets, the issue of collation into the correct sorting sequence needs to be managed properly. In JavaScript, this issue is largely confined to the way that Array objects manage their sort() method's behavior. Date and time formats tend to be arranged differently in each country. The United States and the United Kingdom commonly place the day number and month number the opposite way round. For day numbers above 12, this can be detected automatically but otherwise the context needs to be examined to decide which way round these values are. Numeric formats may dictate a different punctuation symbol to be used for the decimal point and thousands separator. Confusingly, the comma and period characters may be used in both contexts. This means that a value could be misinterpreted and might yield a result that is several orders of magnitude in error when parsed. Currency symbols will need some attention. The United States dollars symbol is in the lower 128 character set. The cents symbol is not. The UK pounds symbol is within the lowest 255 characters.
1355
JavaScript Programmer's Reference
Warnings: ❑
❑
Be careful of the following: ❑
Date formats
❑
Time settings
❑
Character sets
❑
Currency symbols
❑
Sort ordering
❑
Decimal points and thousands separators
The entire concept and scope of localization of JavaScript is being discussed as part of the standardization project. This area is prone to change or, at the very least, some definition of a standard conforming behavior. See also:
Character set, Collation sequence, Currency symbol, Date and time, Decimal point (.), Multi-byte character
location (Property) An alias for the window.location property. Availability:
JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
Property/method value type:
Location object
JavaScript syntax:
-
location
-
myWindow.location
See also:
Property attributes: ReadOnly.
1356
Window.navigate(), Window.location
L – Location object (Object/DOM)
Location object (Object/DOM) An object that represents the location of a document. Availability:
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
Inherits from:
Url object
JavaScript syntax:
-
Object properties: Object methods: Event handlers:
myLocation = myWindow.location
hash, host, hostname, href, pathname, port, protocol, search, target, text, x, y assign(), reload(), replace() onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp
This is a more or less portable encapsulation of a URL value and is most commonly used to describe the location of a document in a window. Changing its href property value has become the preferred means of loading a new document into a window or frame. This is useful because it can also operate very conveniently across frame boundaries. That is, a script in one frame can modify the contents of another. There are some security implications when accessing frames from different servers or domains. These can overcome in Netscape by using signed scripts. Anchor object, Area object, Document.location, LINK object, Map object, URL, Url object, Window.location, Window.navigate()
See also:
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
hash host hostname href pathname port protocol search target text x y
1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.2 + 1.2 + 1.2 +
1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + -
2.0 + 2.0 + 2.0 + 2.0 + 2.0 + 2.0 + 2.0 + 2.0 + 2.0 + 4.0 + 4.0 + 4.0 +
3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + -
3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + -
1+ 1+ 1+ 1+ 1+ 1+ 1+ 1+ -
-
ReadOnly. -
1357
JavaScript Programmer's Reference
Method
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
assign()
1.0 +
1.0 +
2.0 +
3.02 +
-
-
-
Warning, Deprecated
reload()
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
1+
-
-
replace()
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
1+
-
-
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onClick onDblClick onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp
1.0 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.1 + 1.0 + 1.2 +
1.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 1.0 + 3.0 +
2.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 3.0 + 2.0 + 4.0 +
3.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 3.0 + 4.0 +
3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +
-
4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +
Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning
Inheritance chain: Element object, Node object, Url object
Location.assign() (Method) Equivalent to setting the HREF attribute to load a new page. Availability:
JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Deprecated
JavaScript syntax:
-
myLocation.assign(aURL)
Argument list:
aURL
A new URL to load into the location.href
This is functionally equivalent to making an assignment with an equals (=) operator.
Warnings: ❑
This method was not originally intended for use by script level code and should be avoided. See also:
1358
Assign value (=)
L – Location.hash (Property)
Location.hash (Property) The hash target portion of the href property. (The hash after the URL refers to an anchor location in the document). Availability:
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
See also:
Anchor.hash, Url.hash
myLocation.hash
Location.host (Property) The hostname and port number portion of the href property. Availability:
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
See also:
Anchor.host, Url.host
myLocation.host
Location.hostname (Property) The hostname-only portion of the href property. Availability:
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
See also:
Anchor.hostname, Url.hostname
myLocation.hostname
1359
JavaScript Programmer's Reference
Location.href (Property) The URL for the page currently on display in the window owning this location. Availability:
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
myLocation.href
If you set this property, the window will load the new URL in, and replace the old content with the new. See also:
Anchor.href, Url.href
Location.pathname (Property) The file path portion of the href property. Availability:
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
See also:
Anchor.pathname, Url.pathname
Location.port (Property) The port number within the href property. Availability:
1360
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
myLocation.pathname
L – Location.protocol (Property)
Property/method value type:
Number primitive
JavaScript syntax:
-
See also:
Anchor.port, Url.port
myLocation.port
Location.protocol (Property) The protocol portion of the href property, such as: http:,ftp:,mailto:,file:,etc. Availability:
Property/method value type:
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0 String primitive myLocation.protocol
JavaScript syntax:
-
See also:
Anchor.protocol, IMG.protocol, URL, Url.protocol
Property attributes: ReadOnly.
Location.reload() (Method) Reload the currently displayed page in the window that owns this location object. Availability:
DOM level – 1 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Opera – 3.0
JavaScript syntax:
-
myLocation.reload()
-
myLocation.reload(aFlag)
aFlag
A Boolean flag forcing a reload from the server when set to true
Argument list:
This causes the document that owns the Location object to be reloaded. Any form elements would be reset to their initial values.
1361
JavaScript Programmer's Reference
Unless you specify an unconditional reload, the page will be reloaded from the cache if the file is still in the cache, and caching is still active. This may involve a check on the server to see if the copy in the cache is up to date. If the cache copy is out of date, a new document may be fetched from the server. You can use the keyword unconditional as an argument in the location.reload(true) method call to force a new copy of the document to be fetched from the server regardless of the disposition of any documents in the local cache. This should also defeat any proxies and force them to reload from the server but it depends on how they are configured. Refer to the History.go() topic for details of how to perform a benign soft load. See also:
History.go()
Location.replace() (Method) Load a new page and replace the history entry. Availability:
DOM level – 1 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Opera – 3.0
JavaScript syntax:
-
myLocation.replace(aURL)
Argument list:
aURL
A URL to load into the layer, window or frame this location belongs to
This method is a useful way of loading new pages if you want to make sure the history list does not get filled up with unwanted pages. This makes the back button more useful to the user. While the replace goes on, the existing page will continue to be displayed. This also applies if the replace is called during the portion of a page. The new URL is requested but the browser will continue loading and building the previous page until the web server responds and delivers the new replacement page. Termination of the old page therefore happens when the new page begins to arrive and not when it is first requested.
Location.search (Property) The query portion of the href property. Availability:
1362
DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0
L – Location.target (Property)
Property/method value type:
String primitive
JavaScript syntax:
-
See also:
Anchor.search, Url.search
myLocation.search
Location.target (Property) The target window or frame that a location belongs to when its object represents an tag. Availability:
JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0
Property/method value type:
String primitive
JavaScript syntax:
-
myLocation.target
This yields the value of the TARGET attribute in an , or <MAP> tag. You can assign a new value to this property so that the URL will be directed to a different window or frame. Here are some example target values: ❑
_parent
❑
_self
❑
_top
❑
_blank
❑
Window name
❑
Frame name See also:
Anchor.target, BASE.target, Form.target, Url.target
Location.text (Property) The text contained within the and tags when the location describes an anchor. Availability:
JavaScript – 1.2 Netscape – 4.0
Property/method value type:
String primitive
JavaScript syntax:
N
See also:
Anchor.text, Url.text
myLocation.text
1363
JavaScript Programmer's Reference
Location.x (Property) The X coordinate of the anchor on the client display surface. Availability:
JavaScript – 1.2 Netscape – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
N
myLocation.x
The horizontal position of the object in the display measured in pixels. You can use the x and y coordinates of the object as targets of the scrollTo() method for the window it lives in. See also:
Anchor.x, Area.x, Url.x
Location.y (Property) The Y coordinate of the anchor on the client display surface. Availability:
JavaScript – 1.2 Netscape – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
N
myLocation.y
The vertical position of the object in the display measured in pixels. You can use the x and y coordinates of the object as targets of the scrollTo() method for the window it lives in. See also:
Anchor.y, Area.y, Url.y
locationbar (Property) An alias for the window.locationbar property. Availability:
JavaScript – 1.2 Netscape – 4.0
Property/method value type:
Bar object
JavaScript syntax:
-
locationbar
-
myWindow.locationbar
See also:
1364
Bar object, Window.locationbar
L – Lock object (Object/NES)
Property attributes: ReadOnly.
Lock object (Object/NES) Provides a way of locking objects against multiple simultaneous access by several clients at once. Availability: JavaScript syntax:
JavaScript – 1.2 Netscape Enterprise Server version – 3.0 myLock = Lock NES myLock = new Lock()
NES Object properties:
constructor, prototype
Object methods:
isValid(), lock(), unlock()
In a server back end environment, you may have some objects which you share amongst several sessions. This means that they could be accessed on behalf of several clients all at once. You may want to prevent this happening by locking the object as the first client's request accesses it, and then unlocking it again as the request handler for that client no longer needs access to it. You can create new lock objects with the Lock() constructor. It is good manners to unlock resources as soon as you can so that other processes can carry on running. You should not rely on the script exit handler unlocking the locks you place on objects.
Warnings: ❑
Be careful when you use locks. It is possible to place mutually exclusive locks on objects and introduce a deadlocking situation. There is a potential for this if your script is locking more than one object and the locks are not correctly nested.
❑
If you don't implement locks when necessary, you run the risk of run-time errors as your system can run out of resources. See also:
Netscape Enterprise Server, unwatch(), watch()
Property
JavaScript
JScript
NES
Notes
constructor
1.2 +
-
3.0 +
-
prototype
1.2 +
-
3.0 +
-
Method
JavaScript
JScript
NES
Notes
isValid()
1.2 +
-
3.0 +
-
lock()
1.2 +
-
3.0 +
-
unlock()
1.2 +
-
3.0 +
-
1365
JavaScript Programmer's Reference
Lock() (Constructor) A constructor for creating new Lock objects. Availability:
JavaScript – 1.2 Netscape Enterprise Server version – 3.0
Property/method value type:
Lock object
JavaScript syntax:
NES
See also:
Lock object
new Lock();
Lock.constructor (Property) A reference to the constructor for making new Lock objects. Availability:
JavaScript – 1.2 Netscape Enterprise Server version – 3.0
Property/method value type:
Function object
JavaScript syntax:
NES
myLock.constructor
The constructor is that of the built-in Lock prototype object. You can use this as one way of creating locks although it is more popular to use the new Lock() technique. This property is useful if you have an object that you want to clone but you don't know what sort of object it is. Simply access the constructor belonging to the object you have a reference to.
Lock.isValid() (Method) A method that returns an indication as to the validity of the lock. Availability:
JavaScript – 1.2 Netscape Enterprise Server version – 3.0
Property/method value type:
Boolean primitive
JavaScript syntax:
NES
myLock.isValid()
This method will return a Boolean true value if the Lock is still in force and a Boolean false value if it has been relinquished. See also:
1366
Lock.lock(), Lock.unlock()
L – Lock.lock() (Method)
Lock.lock() (Method) Place a lock on the object. Availability:
JavaScript – 1.2 Netscape Enterprise Server version – 3.0
JavaScript syntax:
NES
myLock.lock()
As you attempt to lock the object, the method first tests the Lock to see if another script already has a lock pending. If it does, then this method stalls and will not return until it can successfully place a lock on the object. That will happen when the previous locking script calls the unlock() method. See also:
Lock.isValid()
Lock.prototype (Property) The prototype for the Lock object that can be used to extend the interface for all Lock objects, by allowing you to add methods and properties. Availability:
JavaScript – 1.2 Netscape Enterprise Server version – 3.0
Property/method value type:
Lock object
JavaScript syntax:
NES
Lock.prototype
NES
myLock.constructor.prototype
See also:
prototype property
Lock.unlock() (Method) Relinquish a lock on the object. Availability:
JavaScript – 1.2 Netscape Enterprise Server version – 3.0
JavaScript syntax:
NES
myLock.unlock()
You should always aim to relinquish a lock as soon as you can. They are not intended for use as a means of reserving server facilities but as a means of preventing clashes between sessions. If the unlocking is successful, then true will be returned, and false otherwise. See also:
Lock.isValid()
1367
JavaScript Programmer's Reference
Logical AND (&&) (Operator/logical) Logical AND of two operands. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
anOperand1 && anOperand2
anOperand1
A Boolean value
anOperand2
Another Boolean value
Argument list:
Traditionally in programming environments, the logical AND operator yields true only when both operands are true. However, the specifics of this are slightly different in JavaScript, and although the results may appear to be functionally the same, there is a subtle but important difference. First, lets deal with the normal and expected behavior of a Logical AND operator. The truth table shows the result of this operator for two Boolean primitive values: A
B
AND
false
false
false
false
true
false
true
false
false
true
true
true
Now, the implementation is expected to conform to the ECMA standard. This sets out the following method of evaluation for a Logical AND operator: ❑
Evaluate and convert the first operand using the ToBoolean() method.
❑
If it is false, then evaluate and return the second operand.
❑
Otherwise return the evaluation of the first operand.
To all intents and purposes the external perceived behavior is the same because another ToBoolean() conversion is likely to take place in the context that the expression is used – an if() statement or an outer logical expression for example. The associativity is from left to right. Refer to the operator precedence topic for details of execution order. The result is the Boolean value true if both operands are true, otherwise Boolean false is returned.
1368
L – Logical AND (&&) (Operator/logical)
Example code: A B AND <SCRIPT> for(a=0; a<2; a++) { for(b=0; b<2; b++) { document.write(""); document.write(Boolean(a)); document.write(" "); document.write(Boolean(b)); document.write(" "); document.write(Boolean(a && b)); document.write(" "); } }
See also:
Associativity, Binary logical operator, Bitwise AND (&), Bitwise AND then assign (&=), Logical expression, Logical operator, Operator Precedence
Cross-references: ECMA 262 edition 2 – section – 11.11 ECMA 262 edition 3 – section – 11.11
1369
JavaScript Programmer's Reference
Logical constant (Definition) A Boolean constant value. There are only two possible values for a Boolean constant. That is true or false. A Boolean variable may contain the value undefined. See also:
Constant expression
Logical entity (Definition) Boolean logical values are represented as an entity internally. Availability:
ECMAScript edition – 2
Logical entities always evaluate as a Boolean result. Logical entities are used to form conditions and control branching among other uses. They are often used to hold state information or control switches. A logical entity may be the result of a relational expression or the use of one or more logical operators. A logical entity may be the result of enquiring the property of an object that returns a Boolean value as a result. Logical entities can only contain a true or false value.
Cross-references: ECMA 262 edition 2 – section – 4.3.14 ECMA 262 edition 3 – section – 4.3.14
Logical expression (Definition) An expression whose result is a Boolean value. Availability:
ECMAScript edition – 2
Property/method value type:
Boolean primitive
Logical operators perform a test of the Boolean value of the two operands either side of the operator. See also:
Equal to (==), Expression, Greater than (>), Greater than or equal to (>=), Identically equal to (===), Less than (<), Less than or equal to (<=), Logical AND (&&), NOT Equal to (!=), NOT Identically equal to (!==)
Cross-references: ECMA 262 edition 2 – section – 11.11 ECMA 262 edition 3 – section – 11.11
1370
L – Logical NOT – complement (!) (Operator/logical)
Logical NOT – complement (!) (Operator/logical) Logical NOT operator. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
!anOperand
Argument list:
anOperand
A Boolean value to be complemented
The result is the Boolean complement of the operand value. The exclamation mark is the logical negation operator. The operand is evaluated and its result converted to a binary value. The value is then reversed and used to replace the expression in whatever context it has been used. The truth table shows the result of this operator for a Boolean primitive value: A
NOT
false
true
true
false
Although this is classified as a logical operator here, it is also classified as a unary operator since it only has one operand. The associativity is from right to left. Refer to the operator precedence topic for details of execution order.
Example code: A NOT <SCRIPT> for(a=0; a<2; a++) {
1371
JavaScript Programmer's Reference
document.write(""); document.write(Boolean(a)); document.write(" "); document.write(Boolean(!a)); document.write(" "); }
See also:
Associativity, Bitwise NOT – complement ( ~), Logical operator, NOT Equal to (!=), Operator Precedence, Unary expression, Unary operator
Cross-references: ECMA 262 edition 2 – section – 11.4.9 ECMA 262 edition 3 – section – 11.4.9
Logical operator (Definition) An operator that creates a logical (Boolean) expression. Availability:
ECMAScript edition – 2
Property/method value type:
Boolean primitive
Logical operators perform a one bit operation on the Boolean value of the operands. The input values may not be Boolean values but will be converted to a Boolean value using the toBoolean rules for that type. The conversion happens automatically but may not always be what you expect. The JavaScript interpreter is also quite smart, in that it can for some operator and value combinations perform a lazy evaluation. For example if an expression like this is presented: A AND B Then if A is false, B does not need to be evaluated to know that the result will be false. This can significantly speed up the interpreter because evaluating B might have involved an object reference or perhaps an expression evaluation. It almost always would involve a type conversion from some other type to a Boolean value. This suggests you may effect some performance gains by coding your logical operations to take advantage of this. There are specific logical operators in the set for performing logical AND as well as logical OR operations. However, generally speaking any operator that yields a Boolean result could be used in the same place. The following table summarizes the logical operators as well as those, which come under that general heading of providing a Boolean result:
1372
L – Logical operator (Definition)
Operator
Description
&& || ! == != < <= > >=
Logical AND Logical OR Logical NOT Equal to NOT equal to Less than Less than or equal to Greater than Greater than or equal to
The Boolean constants true and false need to be considered too, because they are often used in conditional tests to force the conditions to be true or false. Although they are not operators as such they can be useful when constructing expressions for debugging purposes. Type conversions indicate these relationships: ❑
false becomes 0
❑
true becomes 1
❑
0 becomes false
❑
Any non-zero value becomes true
Note that this is going to lose some information if you convert a non-zero value other than 1 to a Boolean value and back again.
Warnings: ❑
This is not to be confused with the bitwise operators, which yield a 32-bit integer value instead of the Boolean value yielded by a logical expression.
❑
The bitwise operators may yield a value that in other languages is the same as the logical operator. However although in C language, true and false are really integer values, in JavaScript the Boolean and Number values are distinctly different types.
❑
Be careful to use the correct number of ampersands, and vertical bars to select the logical version of the operator. Refer to the Bitwise operator topic for a list of operators to avoid in logical expressions. See also:
Associativity, Binary logical operator, Bitwise operator, Equal to (==), Expression, Greater than (>), Greater than or equal to (>=), Identically equal to (===), Less than (<), Less than or equal to (<=), Logical AND (&&), Logical NOT – complement ( !), Logical OR (||), NOT Equal to (!=), NOT Identically equal to (!==), Operator, Operator Precedence, ToBoolean, Type, Type conversion
Cross-references: ECMA 262 edition 2 – section – 11.11 ECMA 262 edition 3 – section – 11.11 Wrox Instant JavaScript – page – 19
1373
JavaScript Programmer's Reference
Logical OR (||) (Operator/logical) Logical OR of two operands. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
anOperand1 || anOperand2
anOperand1
A Boolean value
anOperand2
Another Boolean value
Argument list:
Traditionally in programming environments, the logical OR operator yields true when either or both of the operands are true. It yields false only when both are false. However, the specifics of this are slightly different in JavaScript and although the results may appear to be functionally the same, there is a subtle but important difference. First, lets deal with the normal and expected behavior of a Logical OR operator. The truth table shows the result of this operator for two Boolean primitive values: A
B
OR
false
false
false
false
true
true
true
false
true
true
true
true
Now, the implementation is expected to conform to the ECMA standard. This sets out the following method of evaluation for a Logical OR operator: ❑
Evaluate and convert the first operand using the ToBoolean() method.
❑
If it is true, then return that operand.
❑
Otherwise evaluate and return the second operand.
To all intents and purposes the external perceived behavior is the same because another ToBoolean() conversion is likely to take place in the context that the expression is used – an if() statement or an outer logical expression for example. The associativity is from left to right. Refer to the operator precedence topic for details of execution order.
1374
L – Logical XOR (Operator/logical)
Example code: A B OR <SCRIPT> for(a=0; a<2; a++) { for(b=0; b<2; b++) { document.write(""); document.write(Boolean(a)); document.write(" "); document.write(Boolean(b)); document.write(" "); document.write(Boolean(a || b)); document.write(" "); } }
See also:
Associativity, Binary logical operator, Logical operator, Operator Precedence
Cross-references: ECMA 262 edition 2 – section – 11.11 ECMA 262 edition 3 – section – 11.11
Logical XOR (Operator/logical) Logically exclusive OR of two values. There isn't really an XOR logical operator, but the Bitwise XOR operator should work fine. This is proven by evaluating the truth table in the example. This seems to work fine even on MSIE where the sign bit exhibits some instability under Bitwise operations.
1375
JavaScript Programmer's Reference
This is the truth table for two Boolean primitive values being operated on with the XOR operator. A
B
XOR
false
false
false
false
true
true
true
false
true
true
true
false
Example code: A B XOR <SCRIPT> for(a=0; a<2; a++) { for(b=0; b<2; b++) { document.write(""); document.write(Boolean(a)); document.write(" "); document.write(Boolean(b)); document.write(" "); document.write(Boolean(a ^ b)); document.write(" "); } }
See also:
Bitwise XOR (^)
long (Reserved word) Reserved for future language enhancements. The inclusion of this reserved keyword in the ECMAScript standard suggests that future versions of ECMAScript may be more strongly typed. This keyword also represents a Java data type and the long keyword allows for the potential extension of JavaScript interfaces to access Java applet parameters and return values.
1376
L – Low order bit (Definition)
See also:
double, float, Integer, java.lang.Long, LiveConnect, Reserved word, short
Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.3
Low order bit (Definition) The least significant bit in an integer value.
1
See also:
1
1
1
1
0
0
0
Bit, Bit-field, Bitwise operator, byte
LValue (Definition) LValues are placed on the left of an assignment. Availability:
ECMAScript edition – 2
An LValue is that expression or identifier reference that can be placed on the left hand side of an assignment. An LValue must be a modifiable entity. These are called Left-Hand-Side expressions in the ECMA standard. The C language refers to these as Locator Values. See also:
= (Assign), Add then assign (+=), Assign value (=), Assignment expression, Bitwise AND then assign (&=), Bitwise OR then assign (|=), Bitwise shift left then assign (<<=), Bitwise shift right and assign (>>=), Bitwise unsigned shift right and assign (>>>=), Bitwise XOR and assign (^=), Concatenate then assign (+=), Conversion, Divide then assign (/=), Left-Hand-Side expression, Multiply then assign (*=), Property value, Remainder then assign (%=), RValue
Cross-references: ECMA 262 edition 2 – section – 11.2 ECMA 262 edition 3 – section – 11.2
1377
M mailbox: URL (Request method) Displays the Netscape Message Center window. You can add keywords to access the individual components within the mailbox as necessary. The following are all valid URL values in Netscape: ❑
mailbox:
❑
mailbox:Inbox
❑
mailbox:Unsent%20Messages
❑
mailbox:Drafts
❑
mailbox:Templates
❑
mailbox:Sent
❑
mailbox:Trash
Each of these will spawn an additional window as required to display the relevant folder within the mailbox. Note that embedded spaces must be URL escaped for them to work. This mechanism does not seem to provide access to sub-folders.
Warnings: ❑
Although Netscape 6.0 supports this request method, its support is incomplete as of the first nonbeta release. See also:
javascript: URL, mailto: URL, nethelp: URL, telnet: URL, URL
M – mailto: URL (Request method)
mailto: URL (Request method) Activates the mail client to send an e-mail message. Open up a mail client application or use the browser's built-in mail client to send a message to the indicated recipient. Netscape supports the predefiniton of the Subject:, Cc: and Bcc: fields in the mailto: URL. This is illustrated in the example. This may not work on other browsers or JavaScript-capable mail clients. Note that you can leave the spaces as they don't need to be escaped in the Subject text. In some versions, you can also define the Body text for the e-mail by appending the Body operator. This is also shown in the example.
Warnings: ❑
This is only allowed under script control if the script has the UniversalSendMail privilege.
Example code: Send Mail Send Mail Send Mail Send Mail Send Mail
See also:
javascript: URL, mailbox: URL, nethelp: URL, UniversalSendMail, URL
main() function (Definition) The main entry point to a procedural language program. Property/method value type:
Implementation defined
Although JavaScript in many circumstances does not have a main() function, in some applications of the language it may be necessary. By implication, the main() function of a JavaScript is the global code that is present in a web page in the <SCRIPT> tags, but is not part of a function declaration body. When embedded in a browser, the language is invoked according to an event model and the browser itself is the main() for the interpreter. Various script based functions are called by the browser.
1379
JavaScript Programmer's Reference
In a server-side environment, a script may be used as the result of a CGI call. In that case, a main() with passed parameters is a more useful facility. In some implementations, the main() function may be used to make the language accessible to C programmers. Languages often borrow from one another and JavaScript borrows heavily from C language and Java. The exact form of the main() function and possibly its name will be implementation dependent and you should check the documentation for the interpreter just make sure it behaves the way you expect. The result of calling the main() function will be implementation specific, but probably an integer. See also:
argc parameter, argv parameter, Execution context, Execution environment, Host environment, Host object
MakeDate() (Time calculation) A date and time algorithm. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
The MakeDate() operator calculates a number of milliseconds from its two arguments. Both arguments must be ECMAScript number values. All of the arguments must be numeric and finite values. The values should be integers. If they are not then the result will be NaN. The day argument is multiplied by the milliseconds per day and the time argument is added to the result. The sum of the two is a millisecond coded date and time value. Although this is called an operator in the standard, its behavior is more like that of a function. It is not part of the formal language implementation but is a useful function to have available, and can be simulated by writing a script-based function. It is documented in the standard to assist in the algorithmic breakdown of the Date method handlers. The result is a date value in milliseconds since the base date. See also:
Cast operator, Date object, Date(), Date.UTC(), Time range, Time value
Cross-references: ECMA 262 edition 2 – section – 15.9.1.13 ECMA 262 edition 3 – section – 15.9.1.13
1380
M – MakeDay() (Time calculation)
MakeDay() (Time calculation) A date and time algorithm. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
The MakeDay() operator calculates a number of days from its three arguments. Each argument must be an ECMAScript number value. All of the arguments must be numeric and finite values. The values should be integers. If they are not then the result will be NaN. The month number is used as a lookup to establish the number of days in the preceding months. This will also take the year number into account because a leap year calculation may be necessary. The standard does not mandate any range checking, however it would be sensible to include range checks in the implementation of this functionality. Although this is called an operator in the standard, its behavior is more like that of a function. It is not part of the formal language implementation, but is a useful function to have available and can be simulated by writing a script-based function. It is documented in the standard to assist in the algorithmic breakdown of the Date method handlers. The result is a day value in milliseconds since the base date. See also:
Cast operator, Date object, Date(), Date.UTC(), Time range, Time value
Cross-references: ECMA 262 edition 2 – section – 15.9.1.12 ECMA 262 edition 3 – section – 15.9.1.12
MakeTime() (Time calculation) A date and time algorithm. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
The MakeTime() operator calculates a number of milliseconds from its four arguments. Each argument must be an ECMAScript number value. All of the arguments must be numeric and finite values. The values should be integers. If they are not then the result will be NaN.
1381
JavaScript Programmer's Reference
The constant time values giving milliseconds per hour, minute and second are used to multiply each argument. The results are then summed to provide an equivalent time in milliseconds. No range checking is performed according to the ECMA standard so some degree of overflow can be expected. Although this is called an operator in the standard, its behavior is more like that of a function. It is not part of the formal language implementation, but is a useful function to have available and can be simulated by writing a script-based function. It is documented in the standard to assist in the algorithmic breakdown of the Date method handlers. The result is a time value since midnight measured in milliseconds. See also:
Cast operator, Date object, Date(), Date.UTC(), Time range, Time value
Cross-references: ECMA 262 edition 2 – section – 15.9.1.11 ECMA 262 edition 3 – section – 15.9.1.11
<MAP TARGET="..."> (HTML Tag Attribute) The frame or window to target by default with the links in an image map. This is a non-standard tag attribute that is used as a means of linking frames and area maps. You should use instead of <MAP TARGET="..."> for portable applications.
Warnings: ❑
Because this is a non-standard HTML tag attribute, most implementations will not support the TARGET attribute on a <MAP> tag. In that case, apply the TARGET attribute to the tags in the map instead. See also:
Anchor.target, Form.target, Map.target, Window.frames[]
Deprecated usage: Yes
1382
M – Map object (Object/HTML)
Map object (Object/HTML) An object that represents a <MAP> tag. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Inherits from:
Element object
JavaScript syntax:
IE
myMap = myDocument.all.anElementID
IE
myMap = myDocument.all.tags("MAP")[anIndex]
IE
myMap = myDocument.all[aName]
-
myMap = myDocument.getElementById(anElementID)
-
myMap = myDocument.getElementsByName(aName) [anIndex] myMap = myDocument.getElementsByTagName ("MAP")[anIndex]
HTML syntax: Argument list:
<MAP> ... anIndex
A reference to an element in a collection
aName
An associative array reference
anElementID
The ID value of an Element object
Object properties:
name, target
Event handlers:
onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp
Collections:
areas[]
The <MAP> tag in the HTML document source is a container for the tags. These all belong to a parent Map object. This is a means of componentizing a client-side image map and building complex non-rectangular shaped areas. A object, Area object, Element object, Location object
See also:
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
name
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
target
1.5 +
3.0 +
6.0 +
4.0 +
-
-
-
-
1383
JavaScript Programmer's Reference
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onClick
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onDblClick
1.5+
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onHelp
-
3.0 +
-
4.0 +
-
-
-
Warning
onKeyDown
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onKeyPress
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onKeyUp
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseDown
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseMove
1.5 +
3.0 +
6.0 +
4.0 +
-
-
4.0 +
Warning
onMouseOut
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseOver
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseUp
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
Inheritance chain: Element object, Node object
Map.areas[] (Collection) A collection of Area objects belonging to the map object. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
Collection object
JavaScript syntax:
-
myMap.areas
The objects instantiated by tags which are part of this image map, are collected together and accessible as a collection. The collection object is referred to by this property.
Property attributes: ReadOnly
1384
M – Map.name (Property)
Map.name (Property) The value of the NAME="..." HTML tag attribute. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMap.name
Objects are identified either by the NAME="..." HTML tag attribute or by the ID="..." HTML tag attribute. Netscape Navigator shows a marginal preference for the name property while MSIE seems slightly better disposed towards the ID property. However, in many cases both browsers support either technique and in some cases will locate items named with either tag as if they existed in a single namespace. See also:
IMG.useMap
Map.target (Property) The target window or frame to which a map applied. Availability:
JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
HTML syntax:
<MAP TARGET="...">
myMap.target
This yields the value of the TARGET attribute in an , or <MAP> tag. You can assign a new value to this property so that the URL will be directed to a different window or frame.
1385
JavaScript Programmer's Reference
Here are some example target values: ❑
_parent
❑
_self
❑
_top
❑
_blank
❑
Window name
❑
Frame name See also:
<MAP TARGET="...">, Anchor.target, BASE.target, Form.target, Url.target
MARQUEE object (Object/HTML) An object that represents a <MARQUEE> HTML tag. Availability:
JScript – 3.0 Internet Explorer – 4.0
Inherits from:
Element object
JavaScript syntax:
IE
myMARQUEE = myDocument.all.anElementID
IE
myMARQUEE = myDocument.all.tags("MARQUEE") [anIndex] myMARQUEE = myDocument.all[aName]
IE HTML syntax: Argument list:
myMARQUEE = myDocument.getElementById(anElementID) myMARQUEE = myDocument.getElementsByName(aName) [anIndex] myMARQUEE = myDocument.getElementsByTagName ("MARQUEE")[anIndex]
<MARQUEE> anIndex
A reference to an element in a collection
aName
An associative array reference
anElementID Object properties:
The ID value of an Element object accessKey, behavior, bgColor, dataFld, dataFormatAs, dataSrc, direction, height, hspace, loop, scrollAmount, scrollDelay, tabIndex, trueSpeed, vspace, width
Object methods:
start(), stop()
Event handlers:
1386
onAfterUpdate, onBlur, onBounce, onClick, onDblClick, onDragStart, onFilterChange, onFinish, onFocus, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onResize, onRowEnter, onRowExit, onScroll, onSelectStart, onStart
M – MARQUEE object (Object/HTML)
The MARQUEE object is only supported by MSIE and provides means of quickly and easily generating a moving ticker display inside the window area. This can be accomplished with Netscape using layers and some interval timed JavaScript function calls to scroll the layer. The MSIE MARQUEE object is a little more aware of Font Metrics than your average script access can achieve. This means making the MARQUEE bounce back and forth when the text hits the edge of the extent rectangle is a lot easier to accomplish in MSIE than in Netscape. See also:
Element object, Input.accessKey
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
accessKey
-
3.0 +
-
4.0 +
-
-
-
-
behaviour
-
3.0 +
-
4.0 +
-
-
-
-
bgColor
-
3.0 +
-
4.0 +
-
-
-
-
dataFld
-
3.0 +
-
4.0 +
-
-
-
-
dataFormatAs
-
3.0 +
-
4.0 +
-
-
-
-
dataSrc
-
3.0 +
-
4.0 +
-
-
-
-
direction
-
3.0 +
-
4.0 +
-
-
-
-
height
-
3.0 +
-
4.0 +
-
-
-
-
hspace
-
3.0 +
-
4.0 +
-
-
-
-
loop
-
3.0 +
-
4.0 +
-
-
-
-
scrollAmount
-
3.0 +
-
4.0 +
-
-
-
-
scrollDelay
-
3.0 +
-
4.0 +
-
-
-
-
tabIndex
-
3.0 +
-
4.0 +
-
-
-
-
trueSpeed
-
3.0 +
-
4.0 +
-
-
-
-
vspace
-
3.0 +
-
4.0 +
-
-
-
-
width
-
3.0 +
-
4.0 +
-
-
-
-
Method
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
start()
-
3.0 +
-
4.0 +
-
-
-
-
stop()
-
3.0 +
-
4.0 +
-
-
-
-
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onAfterUpdate
-
3.0 +
-
4.0 +
-
-
-
-
onBlur
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
-
-
Warning
onBounce
-
3.0 +
-
4.0 +
-
-
-
-
onClick
1.0 +
3.0 +
4.0 +
3.0 +
3.0 +
-
4.0 +
Warning
onDblClick
1.2 +
3.0 +
4.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onDragStart
-
3.0 +
-
4.0 +
-
-
-
-
Table continued on following page
1387
JavaScript Programmer's Reference
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onFilterChange
-
3.0 +
-
4.0 +
-
-
-
-
onFinish
-
3.0 +
-
4.0 +
-
-
-
-
onFocus
1.0 +
3.0 +
2.0 +
4.0 +
3.0 +
-
-
Warning
onHelp
-
3.0 +
-
4.0 +
-
-
-
Warning
onKeyDown
1.2 +
3.0 +
4.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onKeyPress
1.2 +
3.0 +
4.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onKeyUp
1.2 +
3.0 +
4.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseDown
1.2 +
3.0 +
4.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseMove
1.2 +
3.0 +
4.0 +
4.0 +
-
-
4.0 +
Warning
onMouseOut
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseOver
1.0 +
3.0 +
4.0 +
3.0 +
3.0 +
-
4.0 +
Warning
onMouseUp
1.2 +
3.0 +
4.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onResize
1.2 +
3.0 +
4.0 +
4.0 +
-
-
-
Warning
onRowEnter
-
3.0 +
-
4.0 +
-
-
-
-
onRowExit
-
3.0 +
-
4.0 +
-
-
-
-
onScroll
-
3.0 +
-
4.0 +
-
-
-
-
onSelectStart
-
3.0 +
-
4.0 +
-
-
-
-
onStart
-
3.0 +
-
4.0 +
-
-
-
-
Inheritance chain: Element object, Node object
MARQUEE.behaviour (Property) A attribute that controls the motion of the text in the MARQUEE object. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myMARQUEE.behavior
The animated effect in the MARQUEE is controlled by this property. The following values are appropriate: ❑
alternate
❑
scroll
❑
slide
The alternate behavior marches left and then on bouncing into a boundary, marches right until it bounces again.
1388
M – MARQUEE.bgColor (Property)
The scroll and slide behaviors use the direction attribute to control the direction of movement. When set to scroll, the MARQUEE starts empty, the text scrolls in, traverses the MARQUEE and scrolls out again. A complete cycle begins and ends with an empty MARQUEE. When set to slide, the MARQUEE again starts empty, the text scrolls in until it hits a boundary. Then it is simply zapped out and does not scroll away. Again, a complete cycle begins and ends with an empty MARQUEE.
MARQUEE.bgColor (Property) The background color for the area occupied by the MARQUEE object. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myMARQUEE.bgColor
The background can be colored independently of whether an image is loaded into the background of an object. In fact, it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image. See also:
color names, color value
MARQUEE.direction (Property) The direction of movement of the scrolling text in the MARQUEE. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myMARQUEE.direction
A MARQUEE object can scroll in all four cardinal directions. Leftward scrolling is most likely the appropriate setting for textual content written in a Roman script that is read from left to right. Diagonal scrolling is not possible with a MARQUEE but could be implemented using layers in Netscape 4 or an IFRAME in MSIE and Netscape 6.0. The following values are appropriate for this property: ❑
left
❑
right
❑
down
❑
up
1389
JavaScript Programmer's Reference
MARQUEE.height (Property) The height of the area allocated to the MARQUEE object as it appears onscreen. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
IE
myMARQUEE.height
The MARQUEE space is defined by an extent rectangle that surrounds the space occupied by it on the screen. An extent rectangle is that smallest rectangle that completely encloses the item. This property specifies the height of that extent rectangle.
MARQUEE.hspace (Property) The height of the area allocated to the MARQUEE object as it appears onscreen. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
IE
myMARQUEE.hspace
Margins placed around objects are either modified separately with all four margin sides having a different property or by adjusting the horizontal margins and vertical margins using just two values. The hspace property controls the margin to the left and right of the object.
MARQUEE.loop (Property) A count of the number of times the MARQUEE text is to scroll. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
IE
myMARQUEE.loop
You can define the number of cycles the MARQUEE animation will cycle round before stopping. When it stops, the text will remain visible. Continuous looping is specified by setting this property to a value of -1.
1390
M – MARQUEE.scrollAmount (Property)
MARQUEE.scrollAmount (Property) The offset of the text between one scroll cycle and the next. Availability: Property/method value type: JavaScript syntax:
JScript – 3.0 Internet Explorer – 4.0 Number primitive IE
myMARQUEE.scrollAmount
This value is specified in pixels, and controls the distance that the text appears to move on each scroll cycle of the MARQUEE. The larger the number, the faster the scrolling appears to travel.
MARQUEE.scrollDelay (Property) The time-delay in milliseconds between each scroll update. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
IE
myMARQUEE.scrollDelay
A short delay and small scroll distance will consume more CPU time but appear to be a smoother scroll.
MARQUEE.start() (Method) A command method to start the MARQUEE scrolling. Availability:
JScript – 3.0 Internet Explorer – 4.0
JavaScript syntax:
IE
myMARQUEE.start()
You can stop and start the MARQUEE animation whenever you want. Maybe it is appropriate to scroll a MARQUEE when a mouse is positioned over an object. You can call this method as part of a MouseOver event handler. Then, you can call its complementary MARQUEE.stop() method on the MoveMouseOut event handler.
MARQUEE.stop() (Method) A command method to stop the MARQUEE from scrolling. Availability:
JScript – 3.0 Internet Explorer – 4.0
JavaScript syntax:
IE
myMARQUEE.stop()
Refer to: MARQUEE.start()
1391
JavaScript Programmer's Reference
MARQUEE.trueSpeed (Property) A switch attribute that controls whether the browser should honor very small scroll delay times. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
IE
myMARQUEE.trueSpeed
Extremely small delay times may cause the MARQUEE to scroll more than once during each screen retrace interval. It is wasteful of the CPU resources to scroll the MARQUEE faster than the viewer can perceive the changes. A longer delay and greater scroll distance is more efficient although it may appear jerky for extreme settings.
MARQUEE.vspace (Property) The size of a vertical margin above and below the MARQUEE with respect to any adjacent objects. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
IE
myMARQUEE.vspace
Margins placed around objects are either modified separately with all four margin sides having a different property or by adjusting the horizontal margins and vertical margins using just two values. The vspace property controls the margin at the top and bottom of the object.
MARQUEE.width (Property) The width of the area allocated to the MARQUEE object as it appears onscreen. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
IE
myMARQUEE.width
The MARQUEE space is defined by an extent rectangle that surrounds the space occupied by it on the screen. An extent rectangle is that smallest rectangle that completely encloses the item. This property specifies the width of that extent rectangle.
1392
M – Mask() (Filter/visual)
Mask() (Filter/visual) A visual filter for creating a transparent mask. Availability:
JScript – 3.0 Internet Explorer – 4.0
Refer to: Filter – Mask()
MaskFilter() (Filter/visual) Uses the transparent color pixels of an object as a mask. Availability:
JScript – 5.5 Internet Explorer – 5.5
Refer to: Filter – MaskFilter()
Math object (Object/core) A globally available object containing a library of mathematical functions. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0
JavaScript syntax:
-
Object properties:
constructor
Class constants:
E, LN10, LN2, LOG10E, LOG2E, PI, SQRT1_2, SQRT2
Functions:
abs(), acos(), asin(), atan(), atan2(), ceil(), cos(), exp(), floor(), log(), max(), min(), pow(), random(), round(), sin(), sqrt(), tan()
Math
The Math object is merely a single object owned by the Global Object and which cannot be instantiated. It has some named properties, some of which are functions while others are constants. The prototype for the Math prototype object is the Object prototype object.
1393
JavaScript Programmer's Reference
Although it cannot be instantiated, it does have a constructor which in turn has a prototype property. By adding functions to that prototype, you can extend the capabilities of the Math object. Several examples are provided in nearby topics to illustrate the addition of extra trigonometric and hyperbolic functions.
Warnings: ❑
The Math object provides a collection of static constant values by way of properties belonging to the integral Math object. Because the mathematical mechanisms of any application tend to be provided by the operating system, you should find that between different browsers on any particular platform, the values that these constants yield will be very consistent.
❑
The ECMA standard lays down strict values for these properties and in general, the browser manufacturers try to comply – however, there is always the possibility that an implementation may use a non-compliant calculation.
❑
However, it may not be quite so reliable across platforms. You might enumerate one of these constants as you are authoring and then hard code that value into your script. When that script is executed on another platform, even in the same browser, the internal mathematics support may yield a different value.
❑
You should always refer to the static constants using their symbolic names rather than hard code a possibly platform-dependent value into your script.
❑
Note for the trigonometric functions in general that certain implied identities cannot be assumed in JavaScript. For example: ❑
Math.sin(Math.PI/2) may not yield exactly 1
❑
Math.cos(Math.PI) may not return precisely zero
❑
Math.acos(0) may not return the same value as Math.PI
❑
Math.SQRT1_2 may not be exactly equal to the reciprocal of Math.SQRT2
See also:
Constant, Exponent-log function, Global object, Integer arithmetic, Java to JavaScript values, Native object, Object constant, Object object, Range error, Trigonometric function, Type conversion, unwatch(), watch()
Property
JavaScript
JScript
N
IE
Opera
NES
ECMA Notes
constructor
1.0 +
1.0 +
2.0 +
3.02 +
-
-
-
Cross-references: ECMA 262 edition 2 – section – 10.1.5 ECMA 262 edition 2 – section – 15.1.4.1 ECMA 262 edition 2 – section – 15.8 ECMA 262 edition 3 – section – 10.1.5 ECMA 262 edition 3 – section – 15.1.5.1 ECMA 262 edition 3 – section – 15.8
1394
-
M – Math.abs() (Function)
Math.abs() (Function) The absolute value of a positive or negative number. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.abs(aValue)
Argument list:
aValue
Some meaningful numeric value
This function returns the absolute value of the argument. The absolute value of a number is its distance from zero. In general, the result has the same magnitude as the argument but always has a positive sign. Special boundary conditions that affect the results are: Argument
Result
0
0
NaN
NaN
negative infinity
positive infinity
On some implementations, the absolute value of the most negative integer number may not be representable in the positive range. This is not the same as Number.MIN_VALUE and Number.MAX_VALUE. They describe the largest and smallest possible positive floating point values.
Warnings: ❑
It is possible that due to the underlying implementation of the math library, the absolute value of the most negative number may not be representable and it may yield NaN instead.
Example code: <SCRIPT> for(myEnum = 1.5; myEnum > -2; myEnum -= 0.1)
1395
JavaScript Programmer's Reference
{ document.write(myEnum + " " + Math.abs(myEnum) + " "); }
See also:
Integer arithmetic, Integer-value-remainder, Math object, Math.ceil(), Math.floor(), Type conversion
Cross-references: ECMA 262 edition 2 – section – 15.8.2.1 ECMA 262 edition 3 – section – 15.8.2.1
Math.acos() (Function) The inverse cosine of the passed-in value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.acos(aValue)
Argument list:
aValue
Some meaningful numeric value
This function returns the arc-cosine of the argument. Special boundary conditions that affect the results are: Argument
Result
1
0
greater than 1
NaN
less than -1
NaN
NaN
NaN
The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. The result of this method is the arc-cosine of the passed-in value. The result is expressed in radians and ranges from 0 to pi.
1396
M – Math.asin() (Function)
Warnings: ❑
Note that Math.acos(0) may not return the same value as Math.PI. See also:
Math object, Math.asin(), Math.atan(), Math.atan2(), Math.cos(), Math.PI, Math.sin(), Math.tan(), Trigonometric function
Cross-references: ECMA 262 edition 2 – section – 15.8.2.2 ECMA 262 edition 3 – section – 15.8.2.2
Math.asin() (Function) The inverse sine of the passed-in value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.asin(aValue)
Argument list:
aValue
Some meaningful numeric value
This function returns the arc-sine of the argument. Special boundary conditions that affect the results are: Argument
Result
0 greater than 1 less than -1 NaN
0 NaN NaN NaN
The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. The result of this method is the arc-sine of the passed-in value. The result is expressed in radians and ranges from -pi/2 to +pi/2. See also:
Math object, Math.acos(), Math.atan(), Math.atan2(), Math.cos(), Math.sin(), Math.tan(), Trigonometric function
1397
JavaScript Programmer's Reference
Cross-references: ECMA 262 edition 2 – section – 15.8.2.3 ECMA 262 edition 3 – section – 15.8.2.3
Math.atan() (Function) The inverse tangent of the passed-in value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.atan(aValue)
Argument list:
aValue
Some meaningful numeric value
This function returns the arc-tangent of the argument. Special boundary conditions that affect the results are: Argument
Result
0
0
minus infinity
-pi/2
NaN
NaN
plus infinity
+pi/2
The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. The result of this method is the arc-tangent of the passed-in value. The result is expressed in radians and ranges from -pi/2 to +pi/2. See also:
Math object, Math.acos(), Math.asin(), Math.atan2(), Math.cos(), Math.sin(), Math.tan(), Trigonometric function
Cross-references: ECMA 262 edition 2 – section – 15.8.2.4 ECMA 262 edition 3 – section – 15.8.2.4
1398
M – Math.atan2() (Function)
Math.atan2() (Function) The inverse tangent of the slope of the two arguments. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 3.0 Internet Explorer – 4.0 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.atan2(aValue1, aValue2)
Argument list:
aValue1 aValue2
Some meaningful numeric value Some meaningful numeric value
This function computes the quotient of arg2/arg1 and then returns the arc-tangent of the result. It takes into account which quadrant the value falls into according to the signs of the two arguments. It is provided in several languages other than JavaScript for those situations where very large numbers are involved. Traditionally, for this function, the Y argument is placed first and the X argument second. Special boundary conditions that affect the results are: Argument1
Argument2
Result
+infinity
+infinity
+pi/4
+infinity
-infinity
+3pi/4
+infinity
non zero
+pi/2
-infinity
+infinity
-pi/4
-infinity
-infinity
-3pi/4
-infinity
non zero
-pi/2
0
negative
pi * sign of Argument1
0
positive
0
<0
-infinity
-pi
<0
0
-pi/2
>0
-infinity
+pi
>0
0
+pi/2
Any value
NaN
NaN
NaN
Any value
NaN
non zero
+infinity
0
1399
JavaScript Programmer's Reference
The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. The result of this method is the arc-tangent of the slope of the two arguments. The result is expressed in radians and ranges from -pi to +pi. See also:
Math object, Math.acos(), Math.asin(), Math.atan(), Math.cos(), Math.sin(), Math.tan(), Trigonometric function
Cross-references: ECMA 262 edition 2 – section – 15.8.2.5 ECMA 262 edition 3 – section – 15.8.2.5
Math.ceil() (Function) The value rounded up to the next higher integer value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.ceil(aValue)
Argument list:
aValue
A meaningful numeric value
According to the ECMA standard, this function returns the smallest number value that is not less than the argument and is equal to a mathematical integer. If the argument is already an integer, the argument itself is returned. Special boundary conditions that affect the results are: Argument
Result
+infinity
+infinity
-1 < argument > 0
0
-infinity
-infinity
0
0
NaN
NaN
1400
M – Math.constructor (Property)
Note that if the value is negative, the magnitude decreases while it increases for positive numbers. The ceil of 25.4 is 26 whereas the ceil of -25.4 is -25. The result is the input value rounded up to the next higher integer value.
Warnings: ❑
Other reference sources on this function differ as to its functionality. Some indicate that it rounds up to an integer, others that it rounds down. This suggests that some implementations may behave differently since they may use the available documentation to design their interpreter. The ECMA standard is probably the most reliable specification long term since manufacturers will attempt to build ECMA compliance into their implementations as a selling point.
❑
Recent browsers from Microsoft, Netscape and Opera are all compliant with the ECMA standard on this point.
❑
If you are uncertain, you should check the functionality by running some tests. For example, run the test for negative and positive values. Checking a few boundary conditions won't hurt either. See also:
Integer, Integer arithmetic, Integer-value-remainder, Math object, Math.abs(), Math.floor(), Math.round(), Number(), Remainder (%), Remainder then assign (%=), Type conversion
Cross-references: ECMA 262 edition 2 – section – 15.8.2.6 ECMA 262 edition 3 – section – 15.8.2.6
Math.constructor (Property) A means of creating a new Math object. Availability:
JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0
Property/method value type:
Math object
JavaScript syntax:
-
Math.constructor
Both Netscape and MSIE support a constructor property for the Math object. It is unlikely you would ever want to construct a copy of the Math object. However, this is useful not for the purpose of cloning the Math object but so that you can extend it by adding your own properties and methods to its prototype. This technique is demonstrated in the example which appears to add a pythag() function to the Math object although it is really added to the Object() object prototype.
1401
JavaScript Programmer's Reference
Example code: <SCRIPT> // Define a function that extends the capabilities of the Math object function pythag(aValue1, aValue2) { return Math.sqrt((aValue1*aValue1) + (aValue2*aValue2)); } // Register the new function Math.constructor.prototype.pythag = pythag; // Test the Math.pythag() method document.write(Math.pythag(3, 4)) document.write(" ")
Math.cos() (Function) The cosine of the input argument. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.cos(aValue)
Argument list:
aValue
An angle measured in radians
This function returns the cosine of the argument. The argument must be expressed in radians. Special boundary conditions that affect the results are: Argument
Result
+infinity
NaN
-infinity
NaN
0
1
NaN
NaN
The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations math routines and the specific algorithm selected to evaluate this function.
1402
M – Math.cosec() (Simulated functionality)
Warnings: ❑
Note that Math.cos(Math.PI) may not return precisely zero. See also:
Math object, Math.acos(), Math.asin(), Math.atan(), Math.atan2(), Math.PI, Math.sin(), Math.tan(), Trigonometric function
Cross-references: ECMA 262 edition 2 – section – 15.8.2.7 ECMA 262 edition 3 – section – 15.8.2.7
Math.cosec() (Simulated functionality) The cosec() function is not available in JavaScript but can be simulated to aid in the porting of existing code. The example demonstrates how to add the cosec() method to the Math object.
Example code: <SCRIPT> // Add the cosec function to the Math object function cosec(aValue) { return 1/Math.sin(aValue); } // Register the new function Math.constructor.prototype.cosec = cosec; // Test the Math.cosec() method document.write(Math.cosec(2)); document.write(" ")
See also:
Math.cot(), Math.sec()
1403
JavaScript Programmer's Reference
Math.cosh() (Simulated functionality) The cosh() function is not available in JavaScript but can be simulated to aid in the porting of existing code. The example demonstrates how to add the cosh() method to the Math object.
Example code: <SCRIPT> // Add the cosh function to the Math object function cosh(aValue) { var myTerm1 = Math.pow(Math.E, aValue); var myTerm2 = Math.pow(Math.E, -aValue); return (myTerm1+myTerm2)/2; } // Register the new function Math.constructor.prototype.cosh = cosh; // Test the Math.cosh() method document.write(Math.cosh(2)); document.write(" ");
Math.cot() (Simulated functionality) The cot() function is not available in JavaScript but can be simulated to aid in the porting of existing code. The example demonstrates how to add the cot() method to the Math object to provide the capability to calculate cotangents.
Example code: <SCRIPT> // Add the cot function to the Math object function cot(aValue) { return 1/Math.tan(aValue); }
1404
M – Math.E (Constant/static)
// Register the new function Math.constructor.prototype.cot = cot; // Test the Math.cot() method document.write(Math.cot(2)); document.write(" ");
See also:
Math.cosec(), Math.sec()
Math.E (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape Navigator – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.E
The numeric constant value for e, the base of natural logarithms. The resulting value is approximately 2.718281828459045 (to 15 d.p.).
Warnings: ❑
The word approximately is used when describing the result, because the mathematical accuracy of JavaScript implementations leaves something to be desired and there are some strange artifacts in some of the calculations. See also:
Arithmetic constant, Exponent-log function, Floating point constant, Math object, Math.exp()
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.1 ECMA 262 edition 3 – section – 15.8.1.1
1405
JavaScript Programmer's Reference
Math.exp() (Function) The exponential function of the passed-in argument. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.exp(aValue)
Argument list:
aValue
A meaningful numeric value
This function returns the exponential function of the argument (e raised to the power of the argument, where e is the base of the natural logarithms). Special boundary conditions that affect the results are: Argument
Result
+infinity
+infinity
-infinity
0
0
1
NaN
NaN
The exact value yielded by this function may vary slightly from implementation to implementation, due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. See also:
Cross-references: ECMA 262 edition 2 – section – 15.8.2.8 ECMA 262 edition 3 – section – 15.8.2.8
1406
Exponent-log function, Math object, Math.E, Math.LN10, Math.LN2, Math.log(), Math.LOG10E, Math.LOG2E
M – Math.floor() (Function)
Math.floor() (Function) The value is rounded down to the next integer. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape Navigator – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.floor(aValue)
Argument list:
aValue
A meaningful numeric value
Returns the greatest number value that is not greater than the argument and is equal to a mathematical integer. If the argument is already an integer, the argument itself is returned. Special boundary conditions that affect the results are: Argument
Result
+infinity
+infinity
-infinity
-infinity
0
0
0 < argument > 1
0
NaN
NaN
Note that if the value is negative, the magnitude increases while it decreases for positive numbers. The floor of 25.4 is 25 whereas the floor of -25.4 is -26. The result is the input value rounded down to the next integer.
Warnings: ❑
Other reference sources on this function differ as to its functionality. Some indicate that it rounds up to an integer, others that it rounds down. However, all implementations appear to conform to the ECMA specified behavior. See also:
Integer, Integer arithmetic, Integer-value-remainder, Math object, Math.abs(), Math.ceil(), Math.round(), Number(), Remainder (%), Remainder then assign (%=), Type conversion
Cross-references: ECMA 262 edition 2 – section – 15.8.2.9 ECMA 262 edition 3 – section – 15.8.2.9
1407
JavaScript Programmer's Reference
Math.LN10 (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.LN10
This constant provides the numeric value for the natural logarithm of 10. The resulting value value is approximately 2.302585092994046 (to 15 d.p.)
Warnings: ❑
The word approximately is used when describing the result, because the mathematical accuracy of JavaScript implementations leaves something to be desired and there are some strange artifacts in some of the calculations. See also:
Arithmetic constant, Exponent-log function, Floating point constant, Math object, Math.exp()
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.2 ECMA 262 edition 3 – section – 15.8.1.2
Math.LN2 (Constant/static) A mathematical constant value. Availability:
1408
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
M – Math.log() (Function)
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.LN2
This constant provides the numeric value of the natural logarithm of 2. The resulting value returned is approximately 0.693147180559945 (to 15 d.p.) See also:
Arithmetic constant, Exponent-log function, Floating point constant, Math object, Math.exp()
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.3 ECMA 262 edition 3 – section – 15.8.1.3
Math.log() (Function) The natural logarithm of the passed-in value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.log(aValue)
Argument list:
aValue
A meaningful numeric value
This function returns the natural (base e) logarithm of the input argument. This function is the inverse of the Math.exp() function. Special boundary conditions that affect the results are: Argument
Result
+infinity 0 1 <0 NaN
+infinity -infinity 0 NaN NaN
1409
JavaScript Programmer's Reference
The exact value yielded by this function may vary slightly from implementation to implementation, due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. See also:
Exponent-log function, Math object, Math.exp()
Cross-references: ECMA 262 edition 2 – section – 15.8.2.10 ECMA 262 edition 3 – section – 15.8.2.10
Math.LOG10E (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera browser – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.LOG10E
This constant provides the numeric value for the base-10 logarithm of e, the base of natural logarithms. Note that the value of Math.LOG10E is approximately the reciprocal of the value of Math.LN10. The result returned is approximately 0.434294481903252 (to 15 d.p.)
Warnings: ❑
The word approximately is used when describing the result, because the mathematical accuracy of JavaScript implementations leaves something to be desired and there are some strange artifacts in some of the calculations. See also:
Arithmetic constant, Exponent-log function, Floating point constant, Math object, Math.exp()
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.5 ECMA 262 edition 3 – section – 15.8.1.5
1410
M – Math.LOG2E (Constant/static)
Math.LOG2E (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.LOG2E
This constant provides the numeric value for the base-2 logarithm of e, the base of natural logarithms. By inspection, the resulting value returned is 1.4426950408889634 although this may vary from platform to platform.
Warnings: ❑
Note that the value of Math.LOG2E is approximately the reciprocal of the value of Math.LN2. The word approximately is used here, because the mathematical accuracy of JavaScript implementations leaves something to be desired and there are some strange artifacts in some of the calculations. See also:
Arithmetic constant, Exponent-log function, Floating point constant, Math object, Math.exp()
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.4 ECMA 262 edition 3 – section – 15.8.1.4
Math.max() (Function) The maximum of the two or more input arguments is returned. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
1411
JavaScript Programmer's Reference
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.max(aValue1, aValue2, ...)
aValue1
Some meaningful numeric value
aValue2
Some meaningful numeric value
Argument list:
Returns the larger of the two or more arguments. Special boundary conditions that affect the results are: Argument1
Argument2
Result
Any value
NaN
NaN
Any value
The same value
The value
larger
smaller
Argument1
NaN
Any value
NaN
smaller
larger
Argument2
See also:
Math object
Cross-references: ECMA 262 edition 2 – section – 15.8.2.11 ECMA 262 edition 3 – section – 15.8.2.11
Math.min() (Function) The minimum of the two or more input arguments is returned. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.min(aValue1, aValue2, ...)
aValue1
Some meaningful numeric value
aValue2
Some meaningful numeric value
Argument list:
This function returns the smaller of the two or more arguments.
1412
M – Math.PI (Constant/static)
Special boundary conditions that affect the results are: Argument1
Argument2
Result
Any value
NaN
NaN
Any value
The same value
The value
larger
smaller
Argument2
NaN
Any value
NaN
smaller
larger
Argument1
See also:
Math object
Cross-references: ECMA 262 edition 2 – section – 15.8.2.12 ECMA 262 edition 3 – section – 15.8.2.12
Math.PI (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.PI
This constant provides the numeric value for pi, the ratio of circumference of a circle to its diameter. The resulting value returned is approximately 3.141592653589793 (to 15 d.p.)
Warnings: ❑
Note that Math.sin(Math.PI/2) may not yield exactly 1.
❑
Note that Math.cos(Math.PI) may not return precisely zero.
❑
Note that Math.acos(0) may not return the same value as Math.PI.
See also:
Arithmetic constant, Floating point constant, Math object, Math.acos(), Math.cos(), Math.sin()
1413
JavaScript Programmer's Reference
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.6 ECMA 262 edition 3 – section – 15.8.1.6
Math.pow() (Function) The result of raising a value to the power of another value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.pow(aValue1, aValue2)
aValue1
Some meaningful numeric value
aValue2
Some meaningful numeric value
Argument list:
This function returns the result of raising the first argument to the power of the second. Special boundary conditions that affect the results are: Argument1
Argument2
Result
+0
<0
+infinity
+infinity
<0
0
+infinity
>0
+infinity
-0
< 0 and is an even integer
+infinity
-0
< 0 and is an odd integer
-infinity
-infinity
<0
0
-infinity
> 0 and is an even integer
+infinity
-infinity
> 0 and is an odd integer
-infinity
0
>0
0
1
Any value
1
< 0 and finite
finite but non integer
NaN
abs(arg) < 1
+infinity
0 Table continued on following page
1414
M – Math.pow() (Function)
Argument1
Argument2
Result
abs(arg) < 1
-infinity
+infinity
abs(arg) == 1
+infinity
NaN
abs(arg) == 1
-infinity
NaN
abs(arg) > 1
+infinity
+infinity
abs(arg) > 1
-infinity
0
Any value
0
1
Any value
NaN
NaN
NaN
non zero
NaN
The exact value yielded by this function may vary slightly from implementation to implementation, due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. The example shows a simple binary number converter which exhibits some instability in the most significant bit on some platforms.
Warnings: ❑
There are many boundary conditions that make this function hard to understand and therefore hard to diagnose if it goes wrong. Check both of the input arguments in case of doubt. They may have evaluated out to a strange boundary condition that yields unexpected results.
❑
Using MSIE on the Macintosh exhibits a instability when you raise 2 to the power 31 and test the resulting value in a bitwise expression. Netscape works correctly in this circumstance. This is demonstrated in the example.
Example code: <SCRIPT> document.write(-2 + " – " + binary32(-2) document.write(-1 + " – " + binary32(-1) document.write(0 + " – " + binary32(0) + document.write(1 + " – " + binary32(1) + document.write(2 + " – " + binary32(2) + document.write(3 + " – " + binary32(3) + function binary32(aValue) { myArray = new Array(32);
+ " "); + " "); " "); " "); " "); " ");
for(myEnum=0; myEnum<32; myEnum++) { if(aValue & Math.pow(2, myEnum)) { myArray[31-myEnum] = "1"; } else {
1415
JavaScript Programmer's Reference
myArray[31-myEnum] = "0"; } } return myArray.join(""); }
See also:
Math object, Math.sqrt(), Power function, Zero value
Cross-references: ECMA 262 edition 2 – section – 15.8.2.13 ECMA 262 edition 3 – section – 15.8.2.13
Math.random() (Function) Generates a pseudo-random value. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.02 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.random()
The Math.random() function generates and returns a pseudo-random value; a positive value between 0 and 1. The resulting value is chosen randomly (or pseudo randomly) depending on the implementation. In any case, regardless of how it is selected, it should yield a uniform distribution over the range of possible values. The exact value yielded by this function may vary slightly from implementation to implementation, due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to generate the random numbers. Some implementations may provide a way to seed the random number sequence although the ECMAScript standard does not describe this capability. Some implementations provide predictable series of random numbers that always start at the same seed point. The algorithm and strategy is implementation dependent and the standard offers no recommendations as to which is best.
1416
M – Math.round() (Function)
Warnings: ❑
Although this is noted as being available in Netscape 2.02, that only applies to the Unix platform. It wasn't widely available until JavaScript 1.1 was supported in Netscape 3.0 on the remaining platforms. See also:
Math object, Pseudo-random numbers
Cross-references: ECMA 262 edition 2 – section – 15.8.2.14 ECMA 262 edition 3 – section – 15.8.2.14
Math.round() (Function) Rounds to the nearest integer value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape Navigator – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.round(aValue)
Argument list:
aValue
A meaningful numeric value
This function returns the value that is closest to the argument and is a mathematical integer. It rounds the input value to the nearest integer value either rounding up or down as necessary. If the input value is equi-distant from two integer values, the result is rounded up towards positive infinity. If the argument is already an integer, the argument itself is returned. Special boundary conditions that affect the results are: Argument
Result
+infinity -0.5 < arg < 0.5 -infinity 0 NaN
+infinity 0 -infinity 0 NaN
Note that Math.round(3.5) returns the value 4 while Math.round(-3.5) returns the value 3. See also:
Integer arithmetic, Integer-value-remainder, Math object, Math.ceil(), Math.floor(), Number(), Type conversion
1417
JavaScript Programmer's Reference
Cross-references: ECMA 262 edition 2 – section – 15.8.2.15 ECMA 262 edition 3 – section – 15.8.2.15
Math.sec() (Simulated functionality) The sec() function is not available in JavaScript but can be simulated to aid in the porting of existing code. The example demonstrates how to add the sec() method to the Math object to provide the capability to calculate secants.
Example code: <SCRIPT> // Add the sec function to the Math object function sec(aValue) { return 1/Math.cos(aValue); } // Register the new function Math.constructor.prototype.sec = sec; // Test the Math.sec() method document.write(Math.sec(2)); document.write(" ");
See also:
Math.cosec(), Math.cot()
Math.sin() (Function) The sine of the passed in value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.sin(aValue)
Argument list:
aValue
An angle measured in radians
1418
M – Math.sinh() (Simulated functionality)
This function returns the sine of the input argument. The argument value must be expressed in radians. Special boundary conditions that affect the results are: Argument
Result
+infinity
NaN
-infinity
NaN
0
0
NaN
NaN
The exact value yielded by this function may vary slightly from implementation to implementation, due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function.
Warnings: ❑
Note that Math.sin(Math.PI/2) may not yield exactly 1. See also:
Math object, Math.acos(), Math.asin(), Math.atan(), Math.atan2(), Math.cos(), Math.PI, Math.tan(), Trigonometric function
Cross-references: ECMA 262 edition 2 – section – 15.8.2.16 ECMA 262 edition 3 – section – 15.8.2.16
Math.sinh() (Simulated functionality) The sinh() function is not available in JavaScript but can be simulated to aid in the porting of existing code. The example demonstrates how to add the sinh() method to the Math object.
Example code: <SCRIPT> // Add the sinh function to the Math object function sinh(aValue) { var myTerm1 = Math.pow(Math.E, aValue); var myTerm2 = Math.pow(Math.E, -aValue); return (myTerm1-myTerm2)/2; }
1419
JavaScript Programmer's Reference
// Register the new function Math.constructor.prototype.sinh = sinh; // Test the Math.sinh() method document.write(Math.sinh(2)); document.write(" ");
Math.sqrt() (Function) The square root of the input argument. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.sqrt(aValue)
Argument list:
aValue
A meaningful numeric value
This function computes the square root of the input argument. Special boundary conditions that affect the results are: Argument
Result
+infinity
+infinity
0
0
<0
NaN
NaN
NaN
The exact value yielded by this function may vary slightly from implementation to implementation, due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. See also:
Cross-references: ECMA 262 edition 2 – section – 15.8.2.17 ECMA 262 edition 3 – section – 15.8.2.17
1420
Math object, Math.pow()
M – Math.SQRT1_2 (Constant/static)
Math.SQRT1_2 (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.SQRT1_2
This constant returns the numeric value of the square root of 0.5. The resulting value returned is approximately 0.707106781186548 (to 15.d.p.)
Warnings: ❑
Note that the value of Math.SQRT1_2 is approximately the reciprocal of the value of Math.SQRT2. The word approximately is used here, because the mathematical accuracy of JavaScript implementations leaves something to be desired and there are some strange artifacts in some of the calculations. See also:
Arithmetic constant, Floating point constant, Math object, Math.SQRT2
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.7 ECMA 262 edition 3 – section – 15.8.1.7
Math.SQRT2 (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
1421
JavaScript Programmer's Reference
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.SQRT2
This constant provides the value of the square root of 2. The resulting value returned is approximately 1.414213562373095 (to 15 d.p.)
Warnings: ❑
Note that Math.SQRT1_2 may not be exactly equal to the reciprocal of Math.SQRT2. See also:
Arithmetic constant, Floating point constant, Math object, Math.SQRT1_2
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.8.1.8 ECMA 262 edition 3 – section – 15.8.1.8
Math.tan() (Function) The tangent of the input argument. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Math.tan(aValue)
Argument list:
aValue
An angle measured in radians
This function returns the tangent of the input argument. The argument value must be expressed in radians.
1422
M – Mathematics (Definition)
Special boundary conditions that affect the results are: Argument
Result
+infinity
NaN
-infinity
NaN
0
0
NaN
NaN
The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function. Math object, Math.acos(), Math.asin(), Math.atan(), Math.atan2(), Math.cos(), Math.sin(), Trigonometric function
See also:
Cross-references: ECMA 262 edition 2 – section – 15.8.2.18 ECMA 262 edition 3 – section – 15.8.2.18
Mathematics (Definition) Mathematical support. The following table summarizes the support for mathematical computation in JavaScript: Function
Object
Type
Description
abs()
Math
Function
Absolute value of a number
acos()
Math
Function
Inverse cosine
asin()
Math
Function
Inverse sine
atan()
Math
Function
Inverse tangent
atan2()
Math
Function
Inverse tangent of a slope
ceil()
Math
Function
Round up
cos()
Math
Function
Cosine of an angle
E
Math
Constant
Exponential constant
exp()
Math
Function
Exponent function
floor()
Math
Function
Round down
isFinite()
Global
Function
Test for infinity
isNaN()
Global
Function
Test for Not-a-Number
LN10
Math
Constant
Natural log of 10
LN2
Math
Constant
Natural log of 2 Table continued on following page
1423
JavaScript Programmer's Reference
Function
Object
Type
Description
log()
Math
Function
Natural log of a number
LOG10E
Math
Constant
Log to the base 10 of e
LOG2E
Math
Constant
Log to the base 2 of e
max()
Math
Function
Maximum of two values
MAX_VALUE
Number
Constant
Maximum numeric value
min()
Math
Function
Minimum of two values
MIN_VALUE
Number
Constant
Minimum numeric value
NaN
Number
Constant
Not a number
NEGATIVE_INFI NITY parseFloat()
Number
Constant
Negative infinity
Global
Function
Floating point parser
parseInt()
Global
Function
Integer parser
PI
Math
Constant
The value of PI
POSITIVE_INFI NITY pow()
Number
Constant
Positive infinity
Math
Function
A value rased to the power of another
random()
Math
Function
A random value
round()
Math
Function
Truncating round
sin()
Math
Function
Sine of an angle
sqrt()
Math
Function
Square root
SQRT1_2
Math
Constant
Square root of one half
SQRT2
Math
Constant
Square root of two
tan()
Math
Function
Tangent of an angle
You should avoid the use of any of these function names as identifiers unless you are intentionally overriding their behavior by adding function properties (methods) to a prototype. See also:
Arithmetic operator, Error, Integer arithmetic, Integer-value-remainder, Operator, Power function, Range error, Trigonometric function
Matrix() (Filter/visual) A means of applying sophisticated rotation, translate, and scaling effects to an image using matrix transformation. Availability:
Refer to: Filter – Matrix()
1424
JScript – 5.5 Internet Explorer – 5.5
M – MAYSCRIPT (HTML Tag Attribute)
MAYSCRIPT (HTML Tag Attribute) An attribute on the <APPLET> tag to allow Java to access the JavaScript object space. This is an HTML tag attribute that can significantly affect the success or failure to run applets and plugins properly. The MAYSCRIPT attribute must be present in the <APPLET> tag if you have applets that expect to communicate with JavaScript. This is a way of allowing applets to script under the behest of the web page author who may not be the person who programmed the applet. This way, the author has to know and expect the applet to connect to JavaScript before the applet is able to do so. Without this attribute, an applet is not able to access the JSObject class and communicate with the JavaScript environment. The MAYSCRIPT HTML tag attribute is not reflected into the JavaScript environment. See also:
JavaScript embedded in Java, JSObject object
Measurement units (Definition) Style position and size properties use measurement units to locate objects on the screen. Measurement units specify the units of measure of a quantity. These are typically used for length measurement but may also be used for time measurement in aural style sheet properties. The units include the following: Unit
Description
# % cm deg em
A hash precedes hex color triplet values. A percentage of the containing element's value. Absolute measure of a centimeter. A value used for angular positioning of sound sources. A floating point value indicating a fractional portion of the length of an em-dash in the current font. A floating point value used to multiply the height of a small x in the current font. A frequency value for aural style sheets. Absolute measure of an inch. A frequency value for aural style sheets. Absolute measure of a millimeter. A value in milli-seconds (used for aural style durations). Absolute measure of a pica. Absolute measure of a pica (possibly a misprint in some documentation). Absolute measure using a font point size. An integer value measured in pixels on the screen. A value in seconds (used for aural style durations).
ex Hz in kHz mm ms pc pi pt px s
Measurement units referring to a spatial distance on the page are sometimes called Length units.
1425
JavaScript Programmer's Reference
MediaList object (Object/DOM) This object is added to DOM level 2 to support media lists in style sheets. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
JavaScript syntax:
N
myMedialist = new MediaList()
DOM level 2 specifies the following properties for this object: ❑
mediaText
❑
length
DOM level 2 specifies these methods: ❑
item()
❑
deleteMedium()
❑
appendMedium()
Member (Definition) Elements within an object. Members of structures and unions in other languages have some analogy with methods and properties of an object. In a procedural language you can access members of a structure by name. So also can you access properties within an object. A member name is an identifier. The notation for accessing structure members in C language and property values in JavaScript is identical: ❑
anObject.aProperty
❑
aCStruct.aMember
There is a variation in JavaScript that allows properties to be called as functions, thus: ❑
anObject.aFunctionProperty()
This notation can also denote methods that belong to an object. See also:
1426
Method, Namespace
M – Memory allocation (Definition)
Memory allocation (Definition) The process of locating and allocating some memory to store a string or object. See also:
Reference counting, Memory management
Memory leak (Definition) The consumption of memory that is not recoverable. When the reference count for an object is zero, the object can be garbage collected. Also, because there are no references to it, you have no handle by which you can reach it, so if it isn't garbage collected, it will waste the space it occupies. When that happens, you have a memory leak. Memory leaks typically happen in web-based JavaScript when you create and destroy a lot of strings in a loop. Concatenating many strings together and extending one string incrementally is a typical leak-producing technique. Garbage collection generally only happens in web browsers when the page is refreshed. See also:
delete, Garbage collection, Memory management, Object(), Option(), Reference counting, Variable, Window.setInterval(), Window.setTimeout()
Cross-references: Wrox Instant JavaScript – page – 29
Memory management (Definition) The process of organizing and keeping track of memory allocation and de-allocation. Memory management in compiled languages tends to be a primary concern of software developers. Because JavaScript is interpreted and is intended for use by designers as well as developers, a great deal of the complexity of memory management is hidden from view. It is still possible however to design a script that will consume large amounts of memory due to what is called a memory leak. A memory leak is when you allocate some storage and you don't subsequently relinquish it and make it available to the system again. A prime example of a memory leak in the context of a JavaScript execution is the allocation of string data to String variables. When a new assignment is made, the old storage is unlinked from the variable and some new storage is allocated. This means that the storage management is far simpler because the strings tend to grow longer as new values are assigned. However, in a web browser, the discarded string values continue to sit around in memory until the page is refreshed. At that stage, all page local values are purged and the memory is freed.
1427
JavaScript Programmer's Reference
You cannot force a garbage collection in a JavaScript execution session in a web browser other than by setting the location.href of the current page to itself. This has the side effect of reloading the page from the web server, presenting the user with a possibly ugly transition artifact and increasing net traffic. However, this may be far more preferable than consuming 50 Megabytes of memory every few minutes in the client. See also:
Garbage collection, Memory leak
MENU object (Object/HTML) An object that represents the contents of a <MENU> tag. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Inherits from:
Element object
JavaScript syntax:
IE
myMENU = myDocument.all.anElementID
IE
myMENU = myDocument.all.tags("MENU")[anIndex]
IE
myMENU = myDocument.all[aName]
-
myMENU = myDocument.getElementById(anElementID)
-
myMENU = myDocument.getElementsByName(aName)[anIndex] myMENU = myDocument.getElementsByTagName("MENU")[anIndex]
HTML syntax: Argument list:
Object properties: Event handlers:
<MENU> ... anIndex
A reference to an element in a collection
aName
An associative array reference
anElementID
The ID value of an Element object
compact onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart
The DOM level 1 specification refers to this as a MenuElement object. See also:
Element object
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
compact
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
1428
M – MENU.compact (Property)
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onClick onDblClick onDragStart onFilterChange onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onSelectStart
1.0 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.1 + 1.0 + 1.2 + -
1.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 1.0 + 3.0 + 3.0 +
6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + -
4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +
3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + -
-
4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -
Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -
Inheritance chain: Element object, Node object
MENU.compact (Property) An attribute that controls the display of <MENU> items and the amount of space they require on the screen. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
myMENU.compact
Refer to: DL.compact
menubar (Property) An alias for the window.menubar property. Availability:
JavaScript – 1.2 Netscape – 4.0
Property/method value type:
Bar object
1429
JavaScript Programmer's Reference
JavaScript syntax:
See also:
-
menubar
-
myWindow.menubar
Bar object, Window.menubar
Property attributes: ReadOnly.
<META> (HTML Tag) Document meta-information container. Availability:
JavaScript – 1.2 Netscape – 4.0
HTML syntax:
<META HTTP-EQUIV="aName" CONTENT="aValue">
Argument list:
aName
A pseudo header name
aValue
A pseudo header value
The <META> tag is a way of adding information about the document to the document. This information is never intended for display to the user but helps the browser and other server side systems (and proxies) to manage the document. There are many attributes to the <META> tag. We have only covered the ones that are helpful in the context of script development here. The items that are particularly useful to us are the HTTP_EQUIV and CONTENT attributes. These are used to add information to the HTTP response body. The browser can see these values in the <META> tag and interprets them as if they had been part of the HTTP header. So: <META HTTP-EQUIV="name" CONTENT="value"> is understood to be equivalent to an HTTP header like this: name: value As far as JavaScript is concerned, there are two <META> tags that are useful. This one defines the default scripting language: <META HTTP-EQUIV="Content-Script-Type" CONTENT="text/JavaScript">
1430
M – META object (Object/HTML)
If you have access to the server mechanism, you might be able to effect the same things by forcing it to add this header to the response as it goes out: Content-Script-Type: text/JavaScript The second useful <META> tag is used to define the default style definition language. Given all the warnings about JSS not being portable and it having been deprecated, you could use this in your document block: <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/JavaScript"> Again, if you have access to the server mechanism, you might be able to add this header to the response as it goes out: Content-Style-Type: text/JavaScript
Warnings: ❑
Since MSIE does not support JSS and Netscape ignores the tag variants, these <META> tags are of limited use. See also:
<SCRIPT LANGUAGE="...">, <SCRIPT>, <STYLE TYPE="...">, <STYLE>, JavaScript Style Sheets, META object
Cross-references: Wrox Instant JavaScript – page – 52
META object (Object/HTML) An object that represents the contents of a <META> tag. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Inherits from:
Element object
JavaScript syntax:
IE
myMETA = myDocument.all.anElementID
IE
myMETA = myDocument.all.tags("META")[anIndex]
IE
myMETA = myDocument.all[aName]
-
myMETA = myDocument.getElementById(anElementID)
-
myMETA = myDocument.getElementsByName(aName)[anIndex] myMETA = myDocument.getElementsByTagName("META")[anIndex]
HTML syntax:
<META>
1431
JavaScript Programmer's Reference
Argument list:
anIndex
A reference to an element in a collection
aName
An associative array reference
anElementID
The ID value of an Element object
Object properties:
charset, content, httpEquiv, name, scheme, url
Event handlers:
onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp
These tags and their corresponding object instantiations are used to convey hidden information about the document. This information might be useful to a search engine for example. Sometimes the server uses the META information to control the way the pages are cached into a proxy. Likewise, a client browser may use these values to control the local caching and expiry times of a document. There may be several META objects associated with a document. There is no collection object that provides an enumerable set containing only the META objects but you can traverse the document.all[] collection and extract them in MSIE or use the collection returned by the DOM compliant document.getElementsByTagName("META") method which is supported on Netscape 6.0 and recent versions of MSIE. It is possible you might know the unique ID="..." HTML tag attribute value in which case you can access the required object directly. This is not currently supported at all in Netscape 4.0 although, because it is part of the DOM specification, it is added to Netscape 6.0.
Warnings: ❑ ❑
Netscape 6.0 returns an undefined value for the charset property and incorrectly appends it to the content property. For this meta tag: ❑
❑
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
Netscape Navigator 6.0 returns these values: ❑
myMeta.httpEquiv is defined as "Content-Type"
❑
myMeta.content is defined as "text/html; charset=8859-1"
❑
myMeta.charset is undefined
See also:
<META>, Element object, META.charset
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
charset content httpEquiv name scheme url
1.5 + 1.5 + 1.5 + 1.5 + -
3.0 + 3.0 + 3.0 + 3.0 + 5.0 + 3.0 +
6.0 + 6.0 + 6.0 + 6.0 + -
4.0 + 4.0 + 4.0 + 4.0 + 5.0 + 4.0 +
-
1+ 1+ 1+ 1+ -
-
-
1432
M – META.charset (Property)
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onClick onDblClick onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp
1.0 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.1 + 1.0 + 1.2 +
1.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 1.0 + 3.0 +
6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 +
4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +
3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +
-
4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +
Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning
Inheritance chain: Element object, Node object
META.charset (Property) A value containing the character encoding of the content in the <META> tag. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myMETA.charset
This would contain the character set being used by the document referred to by the HREF="..." HTML tag attribute. For example the value "iso-8859-1" is likely to be returned but the local variant of the browser and OS may affect the value you get. This property might contain a value such as: csISO5427Cyrillic Details of other aliases can be located at the IANA registry. See also:
META object, META.content
Web-references: ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets
1433
JavaScript Programmer's Reference
META.content (Property) The contents of the VALUE="..." HTML tag attribute belonging to the <META> tag that the object represents. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMETA.content
A <META> tag will contain a name-value pair stored in two separate HTML tag attributes. The content property relates to the value part of that name-value pair. The name property is contained in a NAME="..." HTML tag attribute. The web server hides additional information in header records that the client browser uses, but which are invisible to the user and generally hard to access from JavaScript. The <META> tags support an HTTP-EQUIV="..." HTML tag attribute which, although encoded as part of the document source, will behave as if it were a server response header value. This is also used in conjunction with the content property as an alternative way of forming a name-value pair. See also:
META.charset, META.httpEquiv
META.httpEquiv (Property) The contents of the HTTP-EQUIV="..." HTML tag attribute belonging to the <META> tag that the object represents. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMETA.httpEquiv
This property will also reflect the value of the NAME-="..." HTML tag attribute if that was used in preference to the HTTP-EQUIV="..." HTML tag attribute. However only one or the other may be present in the <META> tag in the document source. This property is used in conjunction with the content property to construct a name-value pair. See also:
1434
META.content
M – META.name (Property)
META.name (Property) The name of the meta information this object describes. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMETA.name
This is the value of the NAME="..." HTML tag attribute in the <META> tag that instantiated this object.
META.scheme (Property) A describer for the content form. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMETA.scheme
The meta data in the tags may use the same names in a name=value pair to mean something different according to who defined the meta tag contents. The scheme property reflects the SCHEME="..." HTML tag attribute and defines separate namespaces so the meta information can be interpreted more correctly. It offers a context within which the meta data values are defined.
META.url (Property) A special MSIE supported property containing the URL associated with a <META> tag. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myMETA.url
Occasionally, most likely in an auto-refresh META tag, you will need to specify a URL value. An autorefresh tag uses a client-pull technique to request a page update automatically after a timed interval.
1435
JavaScript Programmer's Reference
Metacharacter (Definition) A special symbolic way of describing some property of a character. Used in regular expressions.
Refer to: RegExp pattern
Method (Definition) A method is an action that can be performed on an object. Availability:
ECMAScript edition – 2
Functions are implemented in the script interpreter objects and are accessed as methods when they are themselves associated with an object. Methods are owned by objects. An instance of a class can own some private methods, which it does not share. It can also share methods it inherits from its prototype. Privately owned methods are sometimes called instance methods. Those functions that are associated with the Global object do not need an object prefix to be used. The Global object is always present and available and in the scope chain and prototype inheritance tree. Therefore the identifiers for those functions can be resolved easily, and in your script code they appear to be like functions in C language. When you declare functions in your script, as they are constructed they are associated with the Global object and are also available in the same way. Functions associated with the Math object require the Math object to be cited when they are called. Because they are visibly associated with the object and are called via the object, they are methods. You can specifically associate one of your own functions with an object other than the Global object. If you do that, then you can refer to the owner object with the variable named 'this'. It is a special variable that is like the 'self' variable in Smalltalk. Because a function is an object and associating it with your own object is by means of a reference to the function object, you can share function code between several objects. So, a method is simply a function that is written in a particular way that means it works well when associated with an object. As soon as you start to use the 'this' variable, then it's likely your function is no longer useful as a stand-alone function and ought to really be called as a method from that point onwards.
1436
M – Microsoft TV (TV Set-top Box)
Example code: // Function to print an owner object property function my_name() { document.write(this.name); } // Create a new object instance var myObject = new Object; // Define the name property for the object myObject.name = "Example"; // Associate the function so it can be used as a method, // note that we omit the parentheses myObject.my_name = my_name; // Call the function via the method interface myObject.my_name(); // Call the function normally my_name();
See also:
Accessor method, Function, function( ... ) ..., java.util, Member, Property, Statement, this
Cross-references: ECMA 262 edition 2 – section – 4.3.3 ECMA 262 edition 3 – section – 4.3.3 Wrox Instant JavaScript – page – 30
Microsoft TV (TV Set-top Box) A digital TV set-top box. This is a more enhanced version of the WebTV box. It may well work on analogue but is really intended for deployment in a digital TV environment. The triggering and standard HTML support is defined according to the ATVEF platform specifications, which are evolving and are not yet complete but are looking to be the definitive profile that 'Browser in a box' type of system needs to conform to. Technically, this platform is more advanced than WebTV but it is fundamentally the same. The JavaScript capabilities in this system would be broadly in line with what you would expect a normal PC browser to cope with but there may be a few limitations here and there. There are also likely to be extensions provided as new object types and possibly some additional methods added to existing objects but these would be quite minimal. Detecting that you are running in a set-top box may not always be easy. The user agent values may not tell you that you have a DTV environment available and you may need to be a little more clever and test for the existence of specific object classes. You need to do that in a way that does not cause a run-time error of course. It's a good technique to practice to ensure your scripts run reliably regardless of whether they are designed for use with Microsoft TV or not. See also:
ATVEF, WebTV
1437
JavaScript Programmer's Reference
MIME types (Definition) An Internet standard way of distinguishing between different kinds of container files. The MIME types mechanism was originally developed for sending attachments in mail messages. Nowadays it has become a commonplace way of describing the content of a document in a way that many non e-mail client applications can understand. This is defined as part of the HTML 4.0 standard. Here is a list of some relevant MIME types for JavaScript programmers: MIMEType
Description
*
Wildcard match everything
*/*
Wild card match both parts separately
application/applefile
AppleSingle file
application/AppleLink
AppleLink Package
application/ArcMac
PC ARChive
application/BBEdit
ML Source
application/binary
Application Binary Data
application/Canvas
Canvas Drawing
application/cdf
Channels
application/CodeWarrior
Java Class File
application/Compact_Pro
Compact Pro Archive
application/DeArj
ARJ Archive
application/DiskCopy
Apple DiskCopy Image
application/Envoy
Envoy Document
application/Excel
Lotus Spreadsheet r2.1
application/FileMaker_Pro
FileMaker Pro Database
application/FileMaker_Pro_3
FileMaker Pro Database
application/Finder
OpenType Font
application/FoxBase+
DBase Document
application/fractals
Fractal Image Format
application/futuresplash
FutureSplash Player
application/GraphicConverter
Animated NeoChrome
application/gzip
application/gzip
application/HexEdit
Untyped Binary Data
application/java-archive
Java Archive
application/JPEGView
OS/2 Bitmap
application/mac-binhex40
Binhex File
application/MacAmp
MPEG-1 Layer 3 Table continued on following page
1438
M – MIME types (Definition)
MIMEType
Description
application/MacAnim_Viewer
DL Animation
application/macbinary
MacBinary
application/MacBooz
Zoo Archive
application/MacLHA
LHArc Archive
application/macwriteii
MacWrite Document
application/Microsoft_Word
Word for Windows Template
application/MoviePlayer
DV Video
application/ms-powerpoint
application/MS-PowerPoint
application/msword
Word Document
application/netcdf
Channels
application/octet-stream
Binary Executable
application/oda
ODA Document
application/PageMaker
PageMaker 3 Document
application/pdf
PDF File
application/PF_Encrypt
Private File
application/pgp-keys
PGP Key File
application/Photoshop
PhotoShop Document
application/PictureViewer
OS/2 Bitmap
application/PlayerPro
669 MOD Music
application/postscript
PostScript File
application/pre-encrypted
Pre-encrypted Data
application/QuarkXpress
QuarkXpress Document
application/Replica
Replica Document
application/ResEdit
Resource File
application/rtf
Rich Text Format File
application/sdp
Session Description Protocol
application/self-extracting
Self-Extracting Archive
application/Self_Extracting_Archive
Self-Extracting Archive
application/SimpleText
Apple documentation file
application/smil
SMIL Document
application/SoftWindows
MS-DOS Executable
application/SoundApp
Amiga OctaMed music
application/SoundHack
IRCAM Sound
application/streamingmedia
Standard Streaming Metafile
application/StuffIt
StuffIt Archive
application/StuffIt_Expander
PackIt Archive
application/SunTar
Unix BAR Archive
application/vnd.fdf
Forms Data Format Table continued on following page
1439
JavaScript Programmer's Reference
MIMEType
Description
application/vnd.lotus-1-2-3
Lotus 123 Document
application/vnd.lotus-approach
Lotus Approach Document
application/vnd.lotus-freelance
Lotus Freelance Document
application/vnd.lotus-organizer
Lotus Organizer Document
application/vnd.lotus-screencam
Lotus ScreenCam Movie
application/vnd.lotus-wordpro
Lotus WordPro Document
application/vnd.ms-access
Microsoft Access Database
application/vnd.ms-excel
Excel Worksheet
application/vnd.ms-powerpoint
PowerPoint Presentation
application/vnd.ms-schedule
Microsoft Schedule+ Application
application/vnd.rn-realmedia
RealMedia File
application/vnd.rn-realplayer
RealPlayer File
application/vnd.rn-realsystem-rjs
RealSystem Skin
application/vnd.rn-realsystem-rmx
RealSystem Secure Media Clip
application/vnd.rn-rn_music_package
RealJukebox Music Package
application/vnd.rn-rsml
RealSystem ML File
application/waf
Website Archive
application/WordPerfect
WordPerfect PC 4.2 Doc
application/wordperfect5.1
WordPerfect PC 5.1 Doc
application/x-authorware-map
Authorware
application/x-cdf
Channels
application/x-compress
Unix Compressed (.z) Files
application/x-compressed
application/x-compressed
application/x-conference
application/x-conference
application/x-cpio
Unix CPIO Archive
application/x-csh
C Shell Program
application/x-director
Shockwave
application/x-dvi
TeX DVI Document
application/x-excel
application/x-excel
application/x-fortezza-ckl
Compromised Key List
application/x-gocserve
CompuServe Inbound Link to CIM 3.0
application/x-gtar
GNU Tape Archive
application/x-gzip
GZIP File
application/x-hdf
HDF Data File
application/x-JavaScript
A .js file containing JavaScript source code
application/x-javascript
JavaScript Program
application/x-javascript-config
JavaScript Config
application/x-javascript-config
JavaScript Config Table continued on following page
1440
M – MIME types (Definition)
MIMEType
Description
application/x-latex
LaTeX Document
application/x-macbinary
MacBinary File
application/x-netcdf
Channels
application/x-ns-proxy-autoconfig
Proxy Auto-Config
application/x-perl
Perl Program
application/x-pkcs7-crl
Certificate Revocation List
application/x-pkcs7-mime
PKCS7 Encrypted Data
application/x-pkcs7-signature
PKCS7 Signature
application/x-rtsp
Real Time Streaming Protocol
application/x-sdp
Scalable Multicast
application/x-sgml
SGML Document
application/x-sh
Bourne Shell Program
application/x-shar
Unix Shell Archive
application/x-shockwave-flash
Shockwave Flash
application/x-stuffit
Stuffit Archive
application/x-tar
TAR Archive
application/x-tcl
TCL Program
application/x-tex
TeX Document
application/x-texinfo
GNU TeXinfo Document
application/x-x509-ca-cert
Certificates
application/x-zip-compressed
Zip Compressed Data
application/xml
HTML Document
application/zip
ZIP Archives
audio/aiff
AIFF Audio
audio/basic
AU Audio
audio/mid
MIDI
audio/midi
MIDI
audio/mp3
MPEG Movie
audio/mpeg
MPEG audio stream
audio/mpegurl
MP3 PlayLists (.m3u,.pls)
audio/mpg
MP3 Audio
audio/rmf
audio/rmf
audio/scpls
MP3 PlayLists (.m3u,.pls)
audio/vnd.qcelp
QCP Audio
audio/vnd.rn-realaudio
RealAudio Clip
audio/wav
WAV Audio
audio/x-aiff
AIFF Audio
audio/x-midi
MIDI Table continued on following page
1441
JavaScript Programmer's Reference
MIMEType
Description
audio/x-mp3
MPEG Movie
audio/x-mpeg
MPEG audio stream
audio/x-mpegurl
MP3 PlayLists (.m3u,.pls)
audio/x-mpg
MP3 Audio
audio/x-pn-realaudio
RealAudio
audio/x-pn-realaudio-plugin
RealPlayer Plugin
audio/x-rmf
audio/x-rmf
audio/x-scpls
MP3 PlayLists (.m3u,.pls)
audio/x-wav
WAV Audio
image/gif
GIF Image
image/ief
IEF image
image/jpeg
JPEG Image
image/pict
PICT Image
image/png
PNG Image
image/tiff
TIFF Image
image/vnd.rn-realflash
RealFlash Clip
image/vnd.rn-realpix
RealPix Clip
image/x-bmp
Windows BMP Image
image/x-cmu-raster
CMU Raster Image
image/x-fits
Flexible Image Transport
image/x-macpaint
MacPaint Image
image/x-macpict
PICT Picture
image/x-MS-bmp
Windows Bitmap
image/x-pbm
Portable Bitmap
image/x-pgm
Portable Graymap
image/x-photo-cd
PhotoCD Image
image/x-photoshop
Photoshop Image
image/x-pict
PICT Image
image/x-png
PNG Image
image/x-portable-anymap
PBM Image
image/x-portable-bitmap
Portable Bitmap
image/x-portable-graymap
Portable Graymap
image/x-portable-pixmap
Portable Pixmap
image/x-ppm
Portable Pixmap
image/x-quicktime
QuickTime Image
image/x-rgb
SGI Image
image/x-sgi
SGI Image
image/x-targa
Targa Truevision Image Table continued on following page
1442
M – MIME types (Definition)
MIMEType
Description
image/x-tiff
TIFF Image
image/x-xbitmap
X Bitmap Image
image/x-xbm
X-Windows Bitmap
image/x-xpixmap
X-Windows Pixmap
image/x-xpm
X-Windows Pixmap
image/x-xwd
X-Windows Dump
image/x-xwindowdump
X Window Dump Image
image/xbitmap
X Bitmap Image
image/xbm
X Bitmap Image
message/external-body
URL Bookmark
Netscape/Source
Special file type
Netscape/Telnet
Netscape Telnet session
Netscape/tn3270
Netscape TN3270 session
text/cdf
Channels
text/css
Text File
text/html
An HTML document.
text/JavaScript
Text formatted JavaScript source code inside a <SCRIPT> block
text/Jscript
Text formatted JScript source code inside a <SCRIPT> block
text/plain
Form content and other plain text documents
text/url
URL File
text/vbs
Text formatted VBScript source code inside a <SCRIPT> block
text/vbscript
Text formatted VBScript source code inside a <SCRIPT> block
text/vnd.rn-realtext
RealText Clip
text/x-cdf
Channels
text/x-vcard
Visiting Card
text/xml
HTML Document
undefined
UUEncoded Data
video/avi
Microsoft Video
video/flc
FLC Animation
video/mpeg
MPEG video/audio stream
video/msvideo
Microsoft Video
video/quicktime
QuickTime Movie
video/vnd.rn-realvideo
RealVideo Clip
video/x-mpeg
MPEG video/audio stream
video/x-mpeg2
MPEG2 Video
video/x-msvideo
Microsoft Video
video/x-qtc
video/x-qtc
x-world/x-3dmf
QuickDraw 3D File
x-world/x-vrml
VRML File
1443
JavaScript Programmer's Reference
MIME stands for Multi-part Internet Mail Extension but its usefulness has gone way beyond the scope of a simple extension to the mail protocols. See also:
<SCRIPT ARCHIVE="...">, <SCRIPT SRC="...">, <SCRIPT TYPE="...">, <STYLE TYPE="...">, Anchor.mimeType, Anchor.type, blob.blobLink(), BUTTON.accept, Document.open(), Form.encoding, JavaScript Image Source URL, LINK.type, MimeType object, MimeType.type, OBJECT.codeType, OBJECT.type, style.cueAfter, style.cueBefore, text/JavaScript, XML.type
Cross-references: Wrox Instant JavaScript – page – 42
MimeType object (Object/browser) An object representing a MIME type. Availability:
JavaScript syntax:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 myMimeType = myWindow.navigator.mimeTypes[anIndex] myMimeType = navigator.mimeTypes[anIndex] -
myMimeType = myMimeTypeArray[anIndex]
Argument list:
anIndex
A reference to an element in a collection
Object properties:
description, enabledPlugin, name, suffixes, type
Collections:
suffixes[]
The example code fragment will list all the available MIME types supported by the browser.
Example code: // List the available mimeTypes for(ii=0; ii
1444
M – MimeType.description (Property)
{ document.write("<no_plugin>"); } document.write(" "); }
MIME types, MimeTypeArray object, Navigator.mimeTypes[]
See also:
Property
JavaScript
JScript
N
IE
Opera
HTML
Notes
description enabledPlugin name suffixes type
1.1 + 1.1 + 1.5 + 1.1 + 1.1 +
3.0 + 3.0 + 5.0 + 3.0 + 3.0 +
3.0 + 3.0 + 6.0 + 3.0 + 3.0 +
4.0 + 4.0 + 5.0 + 4.0 + 4.0 +
-
-
ReadOnly ReadOnly ReadOnly ReadOnly
MimeType.description (Property) The descriptive text for a MIME type. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMimeType.description
This will not be consistent from browser to browser. In some cases there are similarities in the description. In Netscape Navigator there are bugs in the descriptive text content for some MIME types.
Property attributes: ReadOnly.
MimeType.enabledPlugin (Property) The plugin object that handles this MIME type. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
Property/method value type:
Plugin object
JavaScript syntax:
-
myMimeType.enabledPlugin
1445
JavaScript Programmer's Reference
You can use this property to check for the existence of an enabled plugin and generate some kind of dialog that gracefully degrades the performance of your web pages for users who need to download and install a vital plugin module.
Property attributes: ReadOnly.
MimeType.name (Property) The name of this particular MIME type. Availability:
JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMimeType.name
Although the MIME type names are more consistent between browsers than the descriptive text, there are still significant and annoying differences between them. Use with caution as part of your graceful degradation when you find local client support lacks some vital functionality your pages require.
Property attributes: ReadOnly.
MimeType.suffixes[] (Collection) A list of file type suffixes that contain data of this MIME type. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
JavaScript syntax:
-
myMimeType.suffixes
This is another example of cross browser inconsistencies. In addition, the result of accessing this property is not truly a collection but a comma delimited string which needs to be unpacked into an array. In some cases, the string is empty where there are no appropriate file types. Any code you develop needs to take account of the separator being a comma in MSIE and a comma+space in Netscape.
Property attributes: ReadOnly.
1446
M – MimeType.type (Property)
MimeType.type (Property) The name of a MIME type. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
myMimeType.type
This value is the recognized MIME type value for this object. See also:
MIME types
Property attributes: ReadOnly.
MimeTypeArray object (Object/browser) A collection of MimeType objects. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
JavaScript syntax:
-
Object properties:
length
myMimeTypeArray = navigator.mimeTypes
On MSIE, this array contains an element for each supported MimeType object that the browser can respond to. Likewise on Netscape, a collection of somewhat different MimeType objects are available.
Warnings: ❑
MSIE prior to version 5.0 does not support this facility and returns the undefined value even though it has a place holder for the property.
❑
Note that Netscape 4.7 on Macintosh exhibits some careless MimeType instantiation with at least two of the items in this array.
1447
JavaScript Programmer's Reference
❑
Item 50 does not exhibit an associative value because the type property for that MimeType is undefined. There is no apparent fix because the type property of a MimeType object is read-only although there is no error generated when trying to assign a new value to it. The proper type value for this item should be "application.gzip".
❑
Item 64 has a similar problem but just presents a null string rather than its index. This MimeType represents UU encoded files. It doesn't show up in the list of applications that map to file types in the Netscape preferences.
❑
This problem may be extant on other platforms, although it is possible that the problems may be related to your user preference settings and the indices that have problems may not be the same number or MimeType values.
❑
The implications are that GZIP and UU encoded files are handled internally by the browser and therefore, although it creates MimeType objects, they may not be derived from the preferences settings although changing your preferences may relocate these objects to different positions in the collection.
❑
Build an enumerator to examine the MimeType objects in the collection. You'll see a fragment of script that would do this in the example. There is no real fix for this other than to build some conditional check into any enumeration or iterative loop that examines the MimeTypes array.
❑
Note that Netscape 6.0 does not enumerate this collection properly and the example does not yield the correct result, in fact it only seems to work with Netscape 4.
Example code: // Inline this script fragment to display all mime types // supported by your browser (except for NNav 6.0 which exhibits // a strange bug). for(myProp in navigator.mimeTypes) { document.write(myProp); document.write(" "); }
Collection object, MimeType object, Navigator.mimeTypes[]
See also:
Property
JavaScript
JScript
N
IE
Opera
HTML
Notes
length
1.1 +
3.0 +
3.0 +
4.0 +
-
-
ReadOnly
MimeTypeArray.length (Property) The number of discrete MIME types that the browser supports. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
1448
navigator.mimeTypes.length
M – Minima-maxima (Definition)
Property attributes: ReadOnly.
Refer to: Collection.length
Minima-maxima (Definition) Limits for values in the environment or script. The ECMA standard defines some limits for numeric values and the conditions under which it should evaluate numeric values according to the IEEE 754 standard behavior. The standard provides for the implementation to support some enquiry functions so you can determine these limits. The IEEE 754 computation logic further provides for error conditions to be handled gracefully by supplying not a number (NaN) values, infinity and undefined values in cases where a computation would normally generate a domain error and possibly crash the application. If JavaScript did not provide such a forgiving environment in which to execute scripts, it is likely that some of the most trivial script errors would result in the hosting environment crashing. In the context of a web browser you would lose the session and have to restart the browser. On a desktop platform, this could be fatal to the OS and you might have to reboot the machine. See also:
Limits, Range error, Type conversion
Minus (-) (Operator/additive) Subtract one operand from another. Availability:
ECMAScript edition – 2
See also:
Add (+), Additive operator, Subtract (-)
Cross-references: ECMA 262 edition 2 – section – 11.6.2 ECMA 262 edition 2 – section – 11.13 ECMA 262 edition 3 – section – 11.6.2
1449
JavaScript Programmer's Reference
Minus then assign (-=) (Operator/assignment) Subtract the right value from the left, modifying the left value. Availability:
See also:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0 Add then assign (+=), Additive operator, Assignment operator, Decrement value (--), LValue, Subtract then assign (-=)
Cross-references: ECMA 262 edition 2 – section – 11.13 ECMA 262 edition 3 – section – 11.13
mocha: URL (Request method) This is a pseudonym for the JavaScript: URL. It is relevant to Netscape and is probably not supported on other browsers. See also:
URL, javascript: URL
ModElement object (Object/DOM) A DOM level 1 object that describes a modification to a document. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
JavaScript syntax:
-
Object properties:
cite, dateTime
myModElement = new ModeElement()
The MSIE browser implements deletions and insertions as separate object types (DEL and INS respectively). The DOM level 1 standard includes both in a single object class. See also:
1450
DEL object, INS object
M – ModElement.cite (Property)
Property
JavaScript
JScript
N
IE
Opera
DOM
Notes
cite
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
dateTime
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
ModElement.cite (Property) A URL that references a document that describes why the item was modified. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myModElement.cite
The URL of the document that describes why the text was marked as modified is noted in this property. See also:
DEL.cite
ModElement.dateTime (Property) The date and time that the modification occurred. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myModElement.dateTime
This is the date and time value for when the modification change occurred. If you are maintaining change control down to the sub-document level in a content management system, these values can be defined from change records in the database. See also:
DEL.dateTime
1451
JavaScript Programmer's Reference
Modulo (Operator/multiplicative) Modulo operations are called remainder in JavaScript. They may also be called modulus. See also:
Days in year, Multiplicative expression, Remainder (%)
Money (Definition) A locale specific value. See also:
Localization, Currency symbol
Month from time (Time calculation) A date and time algorithm defined by ECMAScript. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
In an ECMA compliant implementation, given a time measured in milliseconds from 01-January1970 UTC, the month number can be calculated from the value. The formula for calculating day number is shown here: Day(t) = floor(t/msPerDay), where: t = an instant in time measured in milliseconds relative to 01-January-1970 UTC. msPerDay = 86400000 All non-leap years have 365 days with the usual number of days in each month. Leap years have an extra day in February. The calculation shown below uses known leap years and non-leap years to adjust the day numbers and yield the day number of the first day of the given year and then use that to work out the time in milliseconds when the year started: DayFromYear(y) = 365 * (y – 1970) + floor((y – 1969) / 4) floor((y – 1901) / 100) + floor((y – 1601) / 400) TimeFromYear(y) = msPerDay * DayFromYear(y) YearFromTime(t) = The largest integer y to make TimeFromYear(y) less than or equal to t. DayWithinYear(t) = Day(t) – DayFromYear(YearFromTime(t))
1452
M – Month from time (Time calculation)
The month value is worked out with this formulaic framework: MonthFromTime(t) = lookup according to DayWithinYear(t) falling into a range according to the following table: Greater than
Less than
Month
Name
000
031
0
January
031
059 + InLeapYear(t)
1
February
059 + InLeapYear(t)
090 + InLeapYear(t)
2
March
090 + InLeapYear(t)
120 + InLeapYear(t)
3
April
120 + InLeapYear(t)
151 + InLeapYear(t)
4
May
151 + InLeapYear(t)
181 + InLeapYear(t)
5
June
181 + InLeapYear(t)
212 + InLeapYear(t)
6
July
212 + InLeapYear(t)
243 + InLeapYear(t)
7
August
243 + InLeapYear(t)
273 + InLeapYear(t)
8
September
273 + InLeapYear(t)
304 + InLeapYear(t)
9
October
304 + InLeapYear(t)
334 + InLeapYear(t)
10
November
334 + InLeapYear(t)
365 + InLeapYear(t)
11
December
Note that MonthFromTime(0) is 0 which corresponds to Thursday, 01-January-1970.
Example code: // Work out a month number from a time value var msPerDay = 86400000; var myMilliseconds = Number(new Date()); document.write(monthFromDayNumber(myMilliseconds)); // Month from day number function monthFromDayNumber(aMillisecondTime) { var myMonthLookup = new Array(); var myDayWithinYear var myYearFromTime var myLeapNumber myMonthLookup[0] = myMonthLookup[1] = myMonthLookup[2] = myMonthLookup[3] = myMonthLookup[4] = myMonthLookup[5] = myMonthLookup[6] = myMonthLookup[7] = myMonthLookup[8] = myMonthLookup[9] = myMonthLookup[10] = myMonthLookup[11] =
= dayWithinYear(aMillisecondTime); = yearFromTime(aMillisecondTime); = +inLeapYear(myYearFromTime); 0; 31; 59 + myLeapNumber; 90 + myLeapNumber; 120 + myLeapNumber; 151 + myLeapNumber; 181 + myLeapNumber; 212 + myLeapNumber; 243 + myLeapNumber; 273 + myLeapNumber; 304 + myLeapNumber; 334 + myLeapNumber;
for(var ii=0; ii<12; ii++) { if(myDayWithinYear < myMonthLookup[ii]) {
1453
JavaScript Programmer's Reference
return ii; } } return 12; } // Work out day number within year based on time value function dayWithinYear(aMilliseconds) { var myDayNumber = dayNumber(aMilliseconds); var myYearFromTime = yearFromTime(aMilliseconds); var myDayFromYear = dayFromYear(myYearFromTime); var myDayWithinYear = myDayNumber – myDayFromYear; return myDayWithinYear; } // Return year number based on time value function yearFromTime(aMilliseconds) { var myStartYear = 1970; while(timeFromYear(myStartYear) < myMilliseconds) { myStartYear++ } return myStartYear-1; } // Work out milliseconds at start of year function timeFromYear(aYear) { var myTime = msPerDay * dayFromYear(aYear); return myTime; } // Work out day number from milliseconds function dayNumber(aMillisecondTime) { var myDay = Math.floor(aMillisecondTime/msPerDay); return myDay; } // Day from year function function dayFromYear(aYear) { var myDay = 365 * (aYear – 1970) + Math.floor((aYear – 1969) / 4) Math.floor((aYear – 1901) / 100) + Math.floor((aYear – 1601) / 400); return myDay; } // Flag a leap year with a Boolean value function inLeapYear(aYear) { if((aYear % 4) != 0) { return false; } if(((aYear % 100) != 0) || ((aYear % 400) == 0)) { return true; } return false; }
See also:
1454
Date from time, Date number, Day from year, Day number, Day within year, Month number, Year from time
M – Month number (Time calculation)
Cross-references: ECMA 262 edition 2 – section – 15.9.1.4 ECMA 262 edition 3 – section – 15.9.1.4
Month number (Time calculation) A date and time algorithm. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
In ECMA compliant implementations, months are identified by an integer in the range 0 to 11, inclusive. The month number is calculated by taking the number of the day at the target time and then taking the day number at the start of that year. The difference is the day number within the year, which can then be used via a compare and lookup mechanism to deduce the month. The InLeapYear() method comes into play to offset the day number by one when it is a leap year. See also:
Day number, Day within year, Month from time, Time range
Cross-references: ECMA 262 edition 2 – section – 15.9.1.4 ECMA 262 edition 3 – section – 15.9.1.4
MotionBlur() (Filter/visual) An enhanced motion blur artefact that replaces the older Blur() filter functionality. Availability:
JScript – 5.5 Internet Explorer – 5.5
Refer to: filter – MotionBlur()
Mouse events (Definition) Mouse events are part of the browser's event handling complex and are triggered by physical interaction with the mouse. These events correspond to user actions as the mouse is moved over various elements on the screen or as the user clicks the mouse buttons.
1455
JavaScript Programmer's Reference
Note that some of these events are triggered in multiples as a result of a single action. For example, as a mouse button is pressed, a mouse-down event is fired. As it is released, a mouse-up and a click event are fired. A click event is only fired once for each mouse-down and mouse-up pair. A double-click requires two down-up cycles within quick succession but the mouse-down and mouse-up events will also fire. The DOM standard refines the event model and creates a specific object class to handle Mouse Events. The event model will evolve as more browsers take on the DOM specified model. See also:
onClick, onDblClick, onMouseDown, onMouseDrag, onMouseMove, onMouseOut, onMouseOver, onMouseUp
MouseEvent object (Object/DOM) This is part of the DOM level 2 mouse event set. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
JavaScript syntax:
N
Object properties:
Object methods:
myMouseEvent = new MouseEvent()
altKey, bubbles, button, cancelable, clientX, clientY, cllientX, ctrlKey, currentTarget, detail, eventPhase, metaKey, relatedTarget, screenX, screenY, shiftKey, target, timeStamp, type, view initEvent(), initMouseEvent(), initUIEvent(), preventDefault(), stopPropagation()
The availability of the MouseEvent object handling can be determined with the Implementation.hasFeature() method call. The available set of events is defined by HTML 4.0 and DOM level 0 with some additional events having been added. These event types are enumerated in the DOM level 2 specification and are: ❑
click
❑
mousedown
❑
mouseup
❑
mouseover
❑
mousemove
❑
mouseout
The contextual information is carried in the detail property which is inherited from the UIEvent object. This value is incremented for each complete mouse click cycle but is reset to zero if the mouse is moved, even if that happens between mousedown and mouseup.
1456
M – MouseEvent object (Object/DOM)
This kind of event is a scenario where event bubbling is likely to be useful because the mouse may click on a pixel sized item which is a child of the object that is really receiving a higher level event. See also:
AbstractView object, Event object, Implementation.hasFeature(), onClick, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, UIEvent object
Property
JavaScript
JScript
Nav
IE
Opera
DOM
Notes
altKey
1.5 +
-
6.0 +
-
-
2+
Warning, ReadOnly
bubbles
1.5 +
-
6.0 +
-
-
2+
-
button
1.5 +
-
6.0 +
-
-
2+
ReadOnly
cancelable
1.5 +
-
6.0 +
-
-
2+
-
clientX
1.5 +
-
6.0 +
-
-
2+
ReadOnly
clientY
1.5 +
-
6.0 +
-
-
2+
ReadOnly
cllientX
1.5 +
-
6.0 +
-
-
2+
-
ctrlKey
1.5 +
-
6.0 +
-
-
2+
ReadOnly
currentTarget
1.5 +
-
6.0 +
-
-
2+
-
detail
1.5 +
-
6.0 +
-
-
2+
-
eventPhase
1.5 +
-
6.0 +
-
-
2+
-
metaKey
1.5 +
-
6.0 +
-
-
2+
Warning, ReadOnly
relatedTarget
1.5 +
-
6.0 +
-
-
2+
ReadOnly
screenX
1.5 +
-
6.0 +
-
-
2+
ReadOnly
screenY
1.5 +
-
6.0 +
-
-
2+
ReadOnly
shiftKey
1.5 +
-
6.0 +
-
-
2+
ReadOnly
target
1.5 +
-
6.0 +
-
-
2+
-
timeStamp
1.5 +
-
6.0 +
-
-
2+
-
type
1.5 +
-
6.0 +
-
-
2+
-
view
1.5 +
-
6.0 +
-
-
2+
-
Method
JavaScript
JScript
Nav
IE
Opera
DOM
Notes
initEvent()
1.5 +
-
6.0 +
-
-
2+
-
initMouseEvent()
1.5 +
-
6.0 +
-
-
2+
-
initUIEvent()
1.5 +
-
6.0 +
-
-
2+
-
preventDefault()
1.5 +
-
6.0 +
-
-
2+
-
stopPropagation()
1.5 +
-
6.0 +
-
-
2+
-
1457
JavaScript Programmer's Reference
MouseEvent.altKey (Property) A Boolean value that represents the state of the [alt] key. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
N
myMouseEvent.altKey
When an event is being processed, you may want to know the state of the [alt] key on the keyboard. This Boolean property returns true when the [alt] key is pressed and false when it is not. This property reflects the state of the [alt] key at the instant when the event was triggered. The user may have released the [alt] key in the meantime so you should not assume that if the [alt] key was pressed earlier on that it is still pressed when the event handler is being executed.
Warnings: ❑
The key may not always be labelled "ALT" on the keyboard. See also:
Event.altKey
Property attributes: ReadOnly.
MouseEvent.button (Property) The mouse button that was pressed to trigger the event. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Number primitive
JavaScript syntax:
N
myMouseEvent.button
If you need to determine which mouse button was pressed to trigger the event, this property will contain a value to indicate the button. Note that on a Macintosh, this value is meaningless as there is only one button on an Apple Macintosh mouse.
1458
M – MouseEvent.clientX (Property)
Third party mice can be added to Apple Macintosh systems to provide multiple (2 or 3) button functionality but they are by no means commonplace and it is probably safe to assume only a 1 button mouse on the Macintosh platform. The values for the buttons are defined to cope with 1, 2 or 3 button mice. The following values correspond with mouse buttons: ❑
0 – No mouse button was pressed when the event was triggered
❑
1 – The left button was pressed
❑
2 – The right button was pressed
❑
3 – The middle button was pressed See also:
Event.button, Event.which
Property attributes: ReadOnly.
MouseEvent.clientX (Property) Mouse position relative to the web page. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Number primitive
JavaScript syntax:
N
myMouseEvent.clientX
This is the horizontal position of the mouse when the event was triggered. The position is calculated relative to the visible document area within the window or frame the mouse was positioned in when the event triggered. See also:
Event.clientX
Property attributes: ReadOnly.
1459
JavaScript Programmer's Reference
MouseEvent.clientY (Property) Mouse position relative to the web page. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Number primitive
JavaScript syntax:
N
myMouseEvent.clientY
This is the vertical position of the mouse when the event was triggered. The position is calculated relative to the visible document area within the window or frame the mouse was positioned in when the event triggered. See also:
Event.clientY
Property attributes: ReadOnly.
MouseEvent.ctrlKey (Property) A Boolean value that represents the state of the [control] key. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
N
myMouseEvent.ctrlKey
When an event is being processed, you may want to know the state of the [control] key on the keyboard. This Boolean property returns true when the [control] key is pressed and false when it is not. This property reflects the state of the [control] key at the instant when the event was triggered. The user may have released the key in the meantime so you should not assume that if the [control] key was pressed earlier on that it is still pressed when the event handler is being executed. See also:
Property attributes: ReadOnly.
1460
Event.ctrlKey
M – MouseEvent.initMouseEvent() (Method)
MouseEvent.initMouseEvent() (Method) After creating a MouseEvent object, it must be initialised with this method call. Availability:
JavaScript syntax:
Argument list:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0 myMouseEvent.initMouseEvent(aType, aBubble, N aCancel, aView, aDetail, aScrnX, aScrnY, aClntX, aClntY, aCtrl, anAlt, aShift, aMeta, aButton, aRelTarg) aType A string value describing the event type aBubble
A boolean flag indicating whether the event can bubble
aCancel
A boolean flag indicating whether the event can be cancelled
aView
A reference to an AbstractView object
aDetail
A value describing the event detail
aScrnX
A screen X coordinate value
aScrnY
A screen Y coordinate value
aClntX
A client X coordinate value
aClntY
A client Y coordinate value
aCtrl
A boolean value indicating the state of the control key
anAlt
A boolean value indicating the state of the alt key
aShift
A boolean value indicating the state of the shift key
aMeta
A boolean value indicating the state of the meta key
aButton
A numeric value indicating which button is being emulated
aRelTarg
A reference to an EventTarget object
A new event object is manufactured by calling the DocumentEvent.createEvent() method. That event should have been defined with a type specified as "MouseEvent". If it was, then it will support an initMouseEvent() method. This must be called before the event is dispatched otherwise the event object will not contain enough information for the event dispatcher/handler to make sense of it and route it to the correct target objects. Two boolean argument values define whether the event will be allowed to be cancelled and what type of propagation to use (bubble or capture). The view argument refers to an AbstractView object which DOM level 2 describes and which may not yet be well supported by any browser. The detail value can be used to pass context information into the event handling chain. The screen and client coordinate values are measured in pixels and must be specified as numeric values. Five boolean values then define the state of keyboard keys when the event was assumed to be triggered. Finally a reference to a related target object is passed. See also:
AbstractView object, EventTarget object, UIEvent.initUIEvent()
1461
JavaScript Programmer's Reference
MouseEvent.metaKey (Property) A Boolean value that represents the state of the [meta] key. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
N
myMouseEvent.metaKey
When an event is being processed, you may want to know the state of the [meta] key on the keyboard. This Boolean property returns true when the [meta] key is pressed and false when it is not. This property reflects the state of the [meta] key at the instant when the event was triggered. The user may have released the [meta] key in the meantime so you should not assume that if the [meta] key was pressed earlier on that it is still pressed when the event handler is being executed.
Warnings: ❑
The key may not always be labelled "META" on the keyboard.
Property attributes: ReadOnly.
MouseEvent.relatedTarget (Property) A related EventTarget object is referred to. Availability:
DOM level – 2 JavaScript – 1.5 Netscape Navigator version – 6.0
Property/method value type:
EventTarget object
JavaScript syntax:
N
myMouseEvent.relatedTarget
The particular EventTarget referred to depends on the event type and context. For example, the standard suggests this might be the object the mouse has just moved off when a mouseOver is being processed. The target and relatedTarget property values would be exchanged vice versa if a mouseOut event were being processed. See also:
Property attributes: ReadOnly.
1462
EventTarget object
M – MouseEvent.screenX (Property)
MouseEvent.screenX (Property) Mouse position relative to the screen display. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Number primitive
JavaScript syntax:
N
myMouseEvent.screenX
You may need to know the position of the mouse relative to the screen display coordinates and not the browser window or objects within it. This property provides the horizontal coordinate of the mouse within the screen. See also:
Event.screenX
Property attributes: ReadOnly.
MouseEvent.screenY (Property) Mouse position relative to the screen display. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Number primitive
JavaScript syntax:
N
myMouseEvent.screenY
You may need to know the position of the mouse relative to the screen display coordinates and not the browser window or objects within it. This property provides the vertical coordinate of the mouse within the screen. See also:
Event.screenY
Property attributes: ReadOnly.
1463
JavaScript Programmer's Reference
MouseEvent.shiftKey (Property) A Boolean value that represents the state of the [shift] key. Availability:
DOM level – 2 JavaScript – 1.5 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
N
myMouseEvent.shiftKey
When an event is being processed, you may want to know the state of the [shift] key on the keyboard. This Boolean property returns true when the [shift] key is pressed and false when it is not. This property reflects the state of the [shift] key at the instant when the event was triggered. The user may have released the key in the meantime so you should not assume that if the [shift] key was pressed earlier on that it is still pressed when the event handler is being executed. See also:
Event.shiftKey
Property attributes: ReadOnly.
moveBy() (Method) An alias for the window.moveBy() method. Availability:
JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0
Property/method value type:
undefined
JavaScript syntax:
-
moveBy(anOffsetX, anOffsetY)
anOffsetX
myWindow.moveBy(anOffsetX, anOffsetY)
anOffsetY
A distance in pixels
Argument list:
1464
A distance in pixels
M – moveTo() (Method)
moveBy()
Delta X
Window.onmove, Window.moveBy()
See also:
moveTo() (Method) An alias for the window.moveTo() method. Availability:
JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0
Property/method value type:
undefined
JavaScript syntax:
-
moveTo(aCoordX, aCoordY)
aCoordX
myWindow.moveTo(aCoordX, aCoordY)
aCoordY
A position in pixels
Argument list:
A position in pixels
Offset X
Offset Y
See also:
Window.onmove, Window.moveTo()
1465
JavaScript Programmer's Reference
MSIE (Web browser) An acronym for the Microsoft web browser. See also:
JScript version, Undocumented features, Web browser, Internet Explorer
Multi-byte character (Definition) Character sets using more than 8 bits to represent a code point. JavaScript natively supports the Unicode character set. This means it is multi-byte character aware at the most fundamental level. Unicode and localization issues are related to one other and the one depends on the other. You cannot effectively localize an environment properly without multi-byte character sets. The extensions to ASCII to make it an international character set were workable but somewhat inconvenient. All manner of escape sequences were required and ultimately, it consumes more space than a multi-byte character would have. Unicode extended the width of the code points from 8 bits to 16. This allows the character set to increase from 256 to 65536 code points. To all intents and purposes, this is sufficient to encode every glyph and character share required by all languages world-wide. However, there may still be some limitations in the encoding used for Far-Eastern language variants. These may be addressed in the Unicode version 3.0 standard. See also:
Character set, Localization, Unicode
Multi-dimensional arrays (Definition) Useful techniques for manipulating matrices for math problems. Multi-dimensional arrays are not supported directly in JavaScript but you can construct them with arrays of arrays. An array can refer to another array with one of its elements. This means you can build multidimensional arrays, which are useful for working out 3D transformations. You probably wouldn't implement a renderer or 3D modeller in JavaScript. However, you might have a Java applet that takes rotation values or perhaps a 3D viewing plugin of some sort that does the hard work.
Warnings: ❑
The arrays are not truly multi-dimensional and you must be careful to construct them properly and avoid damaging them inadvertently.
1466
M – Multi-line comment (Definition)
Example code: // An example shamelessly stolen from Wrox Instant JavaSscript // Create a 2x2 array and store an identity matrix in it. var matrix = new Array(2); matrix[0] = new Array(2); matrix[1] = new Array(2); matrix[0][0] = 1; matrix[1][0] = 0; matrix[0][1] = 0; matrix[1][1] = 1;
See also:
Array index delimiter ([]), Copying objects
Cross-references: Wrox Instant JavaScript – page – 16
Multi-line comment (Definition) Comment blocks that span several lines of script source text. The character sequence /* introduces a multi-line comment. That comment block is terminated by the next occurrence of the */ character sequence. This means you cannot nest these comments within one another. That is arguably bad coding technique anyway. If you are used to C language you will most likely have used conditional compilation blocks controlled via the pre-processor. Most implementations of JavaScript do not support this, however one or two recent implementations, especially those that operate outside the context of a web browser, are beginning to introduce many C language-like facilities. One of those is the preprocessor with its macro directives. This is particularly useful to developers even though it is somewhat non-standard. Multiple line comments are replaced with a single line terminator during the interpretation phase. When the /* ... */ does not have a line terminator inside, it is simply removed prior to interpretation of the remaining line content. Everything between the start and end of a multi-line comment is ignored.
Warnings: ❑
You cannot nest these kinds of comment delimiters within one another. See also:
Comment, Comment (// and /* ... */), Lexical convention, Line
Cross-references: ECMA 262 edition 2 – section – 7.3 ECMA 262 edition 3 – section – 7.4 Wrox Instant JavaScript – page – 17
1467
JavaScript Programmer's Reference
Multiplicative expression (Definition) An expression containing a multiply or divide operator. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
Multiplicative expressions use the multiplicative operators to yield a result by operating on two other values, which may themselves be nested. See also:
Divide (/), Expression, Modulo, Multiplicative operator, Remainder (%)
Cross-references: ECMA 262 edition 2 – section – 11.5 ECMA 262 edition 3 – section – 11.5
Multiplicative operator (Definition) A multiply or divide operator. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
Multiplicative operators are those that require multiplication or division to evaluate their result. The following table lists all operators that are multiplicative and those, which are classified under other categories, which are also multiplicative, by implication: Operator
Description
%
Remainder
*
Multiply
/
Divide
*=
Multiply and assign to an LValue
/=
Divide and assign to an LValue
%=
Remainder and assign to an LValue
Operands that are used with multiplicative operators must have numeric values or be convertible using the valueOf() method.
1468
M – Multiply (*) (Operator/multiplicative)
Warnings: ❑
The order of evaluation of the operands is described in the ECMA standard and a fully compliant implementation should evaluate from left to right. This means that the expression:
❑
myFunctionA() * myFunctionB()
❑
should evaluate myFunctionA() before myFunctionB() and any side effects of executing myFunctionA() will precede those for myFunctionB().
❑
However, you should test this and not rely on it being portable across implementations.
❑
Beware of expressions like this: ❑
0 * myFunction()
❑
Even though you may not have put the zero in as a constant, the operand on the left may evaluate to be zero. Some implementations may provide performance enhancements that depend on eliminating unnecessary computation. A zero multiplied by any other value will yield a zero. The function may never be executed.
❑
If you really want myFunctionA(), myFunctionB() or myFunction() to be executed reliably and in a portable manner, you should evaluate them outside of the expression and assign their results to variables, which you can then use in the expression in their place.
❑
There is a very marginal performance hit but the scripts will execute more reliably across a wider variety of platforms. See also:
Arithmetic operator, Associativity, Binary operator, Divide (/), Divide then assign (/=), Expression, Multiplicative expression, Multiply (*), Multiply then assign (*=), Operator, Operator Precedence, Remainder (%), Remainder then assign (%=)
Cross-references: ECMA 262 edition 2 – section – 11.5 ECMA 262 edition 3 – section – 11.5
Multiply (*) (Operator/multiplicative) Multiply one operand by another. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
anOperand1 * anOperand2
Argument list:
anOperand1 anOperand2
A value to be multiplied The multiplier value
1469
JavaScript Programmer's Reference
The * operator performs multiplication, producing the product of its operands. The multiplication is commutative. That means the operands being multiplied together can be arranged in any order without affecting the outcome as long as they are at the same precedence level. However, the multiplication may not always be associative in ECMAScript compliant interpreters due to finite precision in the evaluations. This means that placing parentheses around the operands may affect the outcome. For example (A * B) * C may not evaluate identically to A * (B * C) to associative artifacts but A * B * C should be identical to B * C * A because of commutation. The rules of floating point multiplication should be governed by the rules of IEEE 754 doubleprecision arithmetic. If either operand is NaN then the result will be NaN. The sign of the result is positive if both operands have the same sign, negative if the operands have different signs. Multiplication of an infinite value by zero results in NaN. Multiplication of infinity by infinity results in infinity. The sign is determined by the sign rules as normal. Multiplying infinity by a finite non-zero value results in a signed infinity. The sign is determined as normal. Otherwise, where neither an infinite value or NaN is involved, the product is computed and rounded to the nearest representable value. If the magnitude of the result is larger than the largest value the interpreter can cope with, an infinity of the appropriate sign is substituted. If the magnitude is too small to be represented, then a zero value is substituted. Note that internally, zero values can be negative or positive and the sign may affect the result of subsequent computations. The associativity is left to right. Refer to the operator precedence topic for details of execution order. See also:
Associativity, Multiplicative operator, Multiply then assign (*=), Operator Precedence
Cross-references: ECMA 262 edition 2 – section – 11.5.1 ECMA 262 edition 2 – section – 11.13 ECMA 262 edition 3 – section – 11.5.1
1470
JavaScript Programmer's Reference
Object methods:
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE appendChild(), cloneNode(), hasChildNodes(), insertBefore(), removeChild(), replaceChild()
Collections:
attributes[], childNodes[]
Class constants:
Here is a list of the available node types: Constant
Type
Description
undefined
null
A member of the attributes collection
ELEMENT_NODE
1
HTML element object node
ATTRIBUTE_NODE
2
HTML tag attribute object
TEXT_NODE
3
Text object node
CDATA_SECTION_NODE
4
CDATA section
ENTITY_REFERENCE_NODE
5
Entity reference
ENTITY_NODE
6
Entity node
PROCESSING_INSTRUCTION_NODE
7
Processing instruction node
COMMENT_NODE
8
Comment node
DOCUMENT_NODE
9
Document object
DOCUMENT_TYPE_NODE
10
Doctype object
DOCUMENT_FRAGMENT_NODE
11
Document fragment node
NOTATION_NODE
12
Notation node
The DOM level 2 specification adds the following methods: ❑
supports()
❑
normalize()
It also adds the following properties: ❑
namespaceURI
❑
prefix
❑
localName
At DOM level 3, the interface to the Node object is expected to evolve further to allow nodes to be compared and to be able to extract a serialized version of a DOM tree branch into a string primitive. This functionality is still under review as this is being written. The following additional properties are expected to be supported: ❑
baseURI
❑
textContent
❑
key
1526
N – Node object (Object/DOM)
DOM level 3 is expected to add the following methods to the Node object: ❑
compareDocumentOrder()
❑
compareTreePosition()
❑
isSameNode()
❑
lookupNamespacePrefix()
❑
lookupNamespaceURI
❑
normalizeNS()
❑
setUserData()
❑
getUserData()
If the implementation supports the DOM level 2 event model (this is the case with Netscape 6.0), then the Node object should also support the methods and properties defined by the EventTarget object. See also:
Attribute.nodeType, Document object, DocumentFragment object, Element object, EventTarget object, MutationEvent.initMutationEvent(), MutationEvent.relatedNode, NamedNodeMap object, Node.firstChild, Node.insertBefore(), Node.lastChild, Node.nextSibling, Node.parentNode, Node.previousSibling
Property
JavaScript
JScript
N
IE
Opera
DOM
Notes
firstChild
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
lastChild
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
nextSibling
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
nodeName
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
nodeType
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
nodeValue
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
ownerDocument
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
parentNode
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
previousSibling
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
Method
JavaScript
JScript
N
IE
Opera
DOM
Notes
appendChild()
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
cloneNode()
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
hasChildNodes()
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
insertBefore()
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
removeChild()
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
replaceChild()
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
1527
JavaScript Programmer's Reference
Node.appendChild() (Method) A new child node object is added to the end of the list of immediate children of this node. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
myNode.appendChild(aNode)
Argument list:
aNode
The node to be appended
Node.attributes[] (Collection) A NamedNodeMap collection of attributes for this node. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
NamedNodeMap object
JavaScript syntax:
-
See also:
Element.attributes[], MutationEvent.attrChange, MutationEvent.attrName, NamedNodeMap object
myNode.attributes
Node.childNodes[] (Collection) A NodeList containing the immediate children of this node. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
NodeList object
JavaScript syntax:
-
See also:
Element.childNodes[], NodeList object
1528
myNode.childNodes
N – Node.cloneNode() (Method)
Node.cloneNode() (Method) The node object is cloned but the new instance has no parent node defined. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
myNode.cloneNode(aSwitch)
aSwitch
Indicates whether a deep or shallow clone is required
Argument list:
Node.firstChild (Property) The first object in the collection of direct children of this element. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
See also:
Element.firstChild, Node object
myNode.firstChild
Node.hasChildNodes() (Method) A convenience method to provide a flag indicating whether there are any children belonging to this node. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
See also:
Element.contains(), Element.firstChild
myNode.hasChildNodes()
1529
JavaScript Programmer's Reference
Node.insertBefore() (Method) This method inserts a child element into the collection at the indicated position. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
myNode.insertBefore(aNode1, aNode2)
aNode1
The node to be inserted
aNode2
The node indicating the insertion point
Argument list:
See also:
Element.insertAdjacentText(), Node object
Node.lastChild (Property) The last child object contained within the DOM hierarchy that descends from this element. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
See also:
Element.lastChild, Node object
myNode.lastChild
Node.nextSibling (Property) An HTML element at the same level within the document hierarchy. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
See also:
Element.nextSibling, Node object
1530
myNode.nextSibling
N – Node.nodeName (Property)
Node.nodeName (Property) The name value for this node object. This is provided by the HTML tag attribute. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
See also:
myNode.nodeName
Element.nodeName
Node.nodeType (Property) The nodes are created for a variety of purposes. This property indicates what sort of node has been instantiated. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Number primitive
JavaScript syntax:
-
myNode.nodeType
The values in this parameter correspond to the values of the Static Constants belonging to the Node Class. Here is a list of the available node types: Constant
Type
Description
undefined
null
A member of the attributes collection
ELEMENT_NODE
1
HTML element object node
ATTRIBUTE_NODE
2
HTML tag attribute object
TEXT_NODE
3
Text object node
CDATA_SECTION_NODE
4
CDATA section
ENTITY_REFERENCE_NODE
5
Entity reference
ENTITY_NODE
6
Entity node Table continued on following page
1531
JavaScript Programmer's Reference
Constant
Type
Description
PROCESSING_INSTRUCTION_NODE
7
Processing instruction node
COMMENT_NODE
8
Comment node
DOCUMENT_NODE
9
Document object
DOCUMENT_TYPE_NODE
10
Doctype object
DOCUMENT_FRAGMENT_NODE
11
Document fragment node
NOTATION_NODE
12
Notation node
See also:
Element.nodeType
Node.nodeValue (Property) The value of the node depends on the kind of node that the object encapsulates. Some nodes have null values. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
See also:
Element.nodeValue
myNode.nodeValue
Node.ownerDocument (Property) The document that the node belongs to can be accessed via this property. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Document object
JavaScript syntax:
-
myNode.ownerDocument
The Node.ownerDocument property is similar to the document property of an Element object. In this case, because we are considering only DOM nodes, whether the document is HTML or not is of no consequence. For now it probably is because the work centers around browser capabilities, but the DOM specification is far more than just a better way to describe a web page.
1532
N – Node.parentNode (Property)
They have very cleverly separated the description of an abstract document and the 'HTMLness' of it into two layers. That way, implementors can superimpose other types of document content on top of a generic DOM foundation built on the Node structure. This property is effectively provided by MSIE version 5 as a property of an Element object. Netscape 6.0 makes it available here in a more DOM-compliant manner. It is a convenience property because accessing a containing document object in this way is far easier than walking down a document.childNode sequence to locate a contained document. See also:
Document object, Element.ownerDocument
Node.parentNode (Property) The direct parent node of the current object. This object will be a member of the childNodes collection for that object. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
See also:
Element.parentNode, MutationEvent.relatedNode, Node object
myNode.parentNode
Node.previousSibling (Property) The object immediately before this one in the childNodes collection of their joint parent node. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
See also:
Element.previousSibling, Node object
myNode.previousSibling
1533
JavaScript Programmer's Reference
Node.removeChild() (Method) A method for removing child nodes from the collection. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
myNode.removeChild(aNode)
Argument list:
aNode
The node object to be removed
Node.replaceChild() (Method) A means of replacing child objects with new nodes and discarding the old ones. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
myNode.replaceChild(newNode, oldNode)
newNode
The node to be placed into the hierarchy
oldNode
The node to be replaced
Argument list:
NodeList object (Object/DOM) A generic collection of nodes, not presented in any particular order.
JavaScript syntax:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0 myNodeList = myDocument.getElements ByTagName(aTagName)
Argument list:
aTagName
Object properties:
length
Object methods:
item()
Availability:
1534
The name of an HTML tag
N – NodeList.item() (Method)
This object is based on an Array object and contains a set of Node items contained within a DOM hierarchy. Do not confuse DOM NodeList arrays with Enumerator or Collection objects. The NodeListitem() method is subtly different to the Enumerator.Item() method. Collection object, Document.getElementsByTagName(), Element.getElementsByTagName(), Enumerator object, NamedNodeMap object, Node.childNodes[]
See also:
Property
JavaScript
JScript
N
IE
Opera
DOM
Notes
length
1.5 +
5.0 +
6.0 +
5.0 +
3.0 +
1+
ReadOnly
Method
JavaScript
JScript
N
IE
Opera
DOM
Notes
item()
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
-
NodeList.item() (Method) An item extractor to retrieve a Node from within a NodeList collection. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Node object
JavaScript syntax:
-
myNodeList.item(anIndex)
Argument list:
anIndex
A numeric index to a Node in the collection
You should node that in MSIE, the Collection object has an Item() method whereas DOM mandates that a NodeList should have an item() method. Note the difference in the case of the initial letter. Even though an implementation may forgive an upper-lower case error when it parses the script source text, an item() call on NodeList can only return a Node object referenced using an integer index location within the collection. Because the NodeList is based on an Array, NodeList.item(anIndex) is functionally equivalent to NodeList[anIndex] and one can enumerate through the set of Node objects using either technique.
1535
JavaScript Programmer's Reference
NodeList.length (Property) Returns the length of a collection array. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
myNodeList.length
The NodeList collection behaves exactly like an Array object and returns a number representing a count of all the Node objects in the collection.
Example code: myCount = document.all.length;
See also:
Array.length, Collection.length
Property attributes: ReadOnly.
NOFRAMES object (Object/HTML) An object that represents the content of a tag. Availability:
JScript – 3.0 Internet Explorer – 4.0
Inherits from:
Element object
JavaScript syntax:
IE
myNOFRAMES = myDocument.all.anElementID
IE
myNOFRAMES = myDocument.all.tags("NOFRAMES") [anIndex] myNOFRAMES = myDocument.all[aName]
IE -
1536
myNOFRAMES = myDocument.getElementById (anElementID) myNOFRAMES = myDocument.getElementsByName (aName)[anIndex] myNOFRAMES = myDocument.getElementsByTagName ("NOFRAMES")[anIndex]
N – NOFRAMES object (Object/HTML)
...
HTML syntax: Argument list:
anIndex
A reference to an element in a collection
aName
An associative array reference
anElementID
The ID value of an Element object
Object properties:
accessKey, tabIndex, dir
Event handlers:
onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp
This was added to the MSIE browser at revision 4. It is a sub-class of the basic Element object and therefore shares many properties with other objects in the MSIE browser. Although it is implemented as an Element, it is not a DOM specified item. Element object, NOSCRIPT object
See also:
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
accessKey
-
3.0 +
-
4.0 +
-
-
-
-
tabIndex
-
3.0 +
-
4.0 +
-
-
-
-
dir
-
5.0 +
-
5.0 +
-
-
-
-
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onClick
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onDblClick
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onHelp
-
3.0 +
-
4.0 +
-
-
-
Warning
onKeyDown
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onKeyPress
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onKeyUp
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseDown
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseMove
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseOut
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseOver
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
onMouseUp
-
3.0 +
-
4.0 +
-
-
4.0 +
Warning
Inheritance chain: Element object, Node object
1537
JavaScript Programmer's Reference
NOFRAMES.dir (Property) The direction of rendering of text contained within the block owned by the tag. Availability:
JScript – 5.0 Internet Explorer – 5.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myNOFRAMES.dir
The dir property may be set to indicate a left-to-right or right-to-left parsing direction. This is part of the localization support and represents the contents of the DIR="..." tag attribute. If you assign a value to this property it is case-sensitive and must be either "ltr" or "rtl". Note that this is at variance with some documentation which says it is case-insensitive. This property works in conjunction with the lang property to control the direction of text flow. See also:
BDO.dir, Element.dir, NOSCRIPT.dir
Nombas ScriptEase (Product) A standalone JavaScript interpreter. This is an example of a JavaScript interpreter than can be used in several contexts. The ScriptEase Web Server Edition (SEWSE) can be used in the backend of a server to accomplish much of what you might do with <SERVER> tags in the Netscape Enterprise Server or with Microsoft ASP. SEWSE is called as part of the CGI mechanism in the web server. The Script Ease Desk Top implementation provides a way to use JavaScript to control desktop actions. This is available cross-platform and accomplishes the kind of things you might do with AppleScript on a Macintosh or Windows Script Host in the Microsoft Windows environment. The SEWSE interpreter can also be used for general purpose scripting in the Unix environment in much the way you would use Bourne, Korn or C shells or the Perl interpreter. You can also embed Script Ease into your own applications and add scriptability to them. See also:
1538
Standalone JavaScript
N – Nondigit (Definition)
Nondigit (Definition) A non-digit letter that can be used in an identifier. In the context of creating identifier names, a non-digit character is a member of the following set: a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ (Underscore) See also:
Digit, Identifier
(HTML Tag) A special tag that allows browsers that don't support scripting to display alternative content. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
Browsers that support the <SCRIPT> tag should also support the tag. However, their support for the tag should be to hide or ignore anything between the tag and its corresponding closure.
Warnings: ❑
This is not supported by Netscape 2. See also:
<SCRIPT>, Compatibility
NOSCRIPT object (Object/HTML) An object representing the tag. Availability:
JScript – 3.0 Internet Explorer – 4.0
Inherits from:
Element object
1539
JavaScript Programmer's Reference
JavaScript syntax:
IE
myNOSCRIPT = myDocument.all.anElementID
IE
myNOSCRIPT = myDocument.all.tags("NOSCRIPT")[anIndex] myNOSCRIPT = myDocument.all[aName]
IE HTML syntax: Argument list:
myNOSCRIPT = myDocument.getElementById(anElementID) myNOSCRIPT = myDocument.getElementsByName(aName)[anIndex] myNOSCRIPT = myDocument.getElementsByTagName ("NOSCRIPT")[anIndex]
... anIndex
A reference to an element in a collection
aName
An associative array reference
anElementID
The ID value of an Element object
Object properties:
accessKey, tabIndex, dir
Event handlers:
onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp
This was added to the MSIE browser at revision 4. It is a sub-class of the basic Element object and therefore shares many properties with other objects in the MSIE browser. Although it is implemented as an Element, it is not a DOM-specified item. See also:
Element object, NOFRAMES object
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
accessKey tabIndex dir
-
3.0 + 3.0 + 5.0 +
-
4.0 + 4.0 + 5.0 +
-
-
-
-
Event name
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
onClick onDblClick onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp
-
3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +
-
4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +
-
-
4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +
Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning
1540
N – NOSCRIPT.dir (Property)
Inheritance chain: Element object, Node object
NOSCRIPT.dir (Property) The direction of rendering of text contained within the block owned by the tag. Availability:
JScript – 5.0 Internet Explorer – 5.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myNOSCRIPT.dir
The dir property may be set to indicate a left-to-right or right-to-left parsing direction. This is part of the localization support and represents the contents of the DIR="..." tag attribute. If you assign a value to this property it is case-sensitive and must be either "ltr" or "rtl". Note that this is at variance with some documentation which says it is case-insensitive. This property works in conjunction with the lang property to control the direction of text flow. See also:
BDO.dir, Element.dir, NOFRAMES.dir
Not a number (Definition) A special numeric value used to handle computational error conditions. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
IEEE 754 describes a numeric regime that includes the ability to flag exceptions when calculations generate invalid results. The result of such an expression may be signified by the NaN or Not a Number exception. See also:
IEEE 754, NaN
Cross-references: ECMA 262 edition 2 – section – 4.3.23 ECMA 262 edition 3 – section – 4.3.23
1541
JavaScript Programmer's Reference
NOT Equal to (!=) (Operator/equality) Compare two operands for inequality. Availability:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
anOperand1 != anOperand2
anOperand1
A value to be compared
anOperand2
Another value to be compared
Argument list:
The two operands are compared, and the Boolean true value is returned if they are not equal, otherwise false if they are equal. Note that JavaScript will attempt to convert both operands to the same type for comparison. When testing for inequality, the following rule is invariant: A != B
is equivalent to: !(A == B)
Also, the rule of positioning allows that: A == B
is identical to: B == A
(Apart from the fact that exchanging the operands in this way alters the order in which they are evaluated.) Exchanging the operands may have undesirable side effects if they are expressions. For example, they may call functions and test the results. If the functions are not totally independent of one another, you may get unexpected results. The associativity is from left to right. Refer to the Operator Precedence topic for details of execution order. Refer to the Equality expression topic for a discussion on the ECMA standard definition of the equality testing rules.
1542
N – NOT Identically equal to (!==) (Operator/identity)
See also:
ASCII, Associativity, Equal to (==), Equality expression, Equality operator, Greater than (>), Greater than or equal to (>=), Identically equal to (===), Less than (<), Less than or equal to (<=), Logical expression, Logical NOT – complement ( !), Logical operator, NOT Identically equal to (!==), Operator Precedence, Relational expression, Relational operator, typeof, Unicode
Cross-references: ECMA 262 edition 2 – section – 11.9.2 ECMA 262 edition 2 – section – 11.9.3 ECMA 262 edition 3 – section – 11.9.2 ECMA 262 edition 3 – section – 11.9.3
NOT Identically equal to (!==) (Operator/identity) Compare two values for non-equality and identical type. Availability:
ECMAScript edition – 3 JavaScript – 1.3 JScript – 1.0 Internet Explorer – 3.02 Netscape – 4.06
Property/method value type:
Boolean primitive
JavaScript syntax:
-
anOperand1 !== anOperand2
anOperand1
A value to be compared
anOperand2
Another value of the same type to be compared
Argument list:
The two operands are compared and Boolean false is returned if both values are equal, and of the same type, otherwise Boolean true is returned. The associativity is from left to right. Refer to the Operator Precedence topic for details of execution order.
Warnings: ❑
This is not available for use server-side with Netscape Enterprise Server 3.
1543
JavaScript Programmer's Reference
Example code: <SCRIPT> myObject1 = 100; myObject2 = "100"; if(myObject1 != myObject2) { document.write("Objects are NOT equal "); } else { document.write("Objects are equal "); } if(myObject1 !== myObject2) { document.write("Objects are NOT identical "); } else { document.write("Objects are identical "); }
See also:
ASCII, Associativity, Equal to (==), Equality expression, Equality operator, Greater than (>), Greater than or equal to (>=), Identically equal to (===), Identity operator, JellyScript, Less than (<), Less than or equal to (<=), Logical expression, Logical operator, NOT Equal to (!=), Operator Precedence, Relational expression, Relational operator, typeof, Unicode
Cross-references: ECMA 262 edition 3 – section – 11.9.5 Wrox Instant JavaScript – page – 39
1544
N – Notation object (Object/DOM)
Notation object (Object/DOM) Notations are decalred in the DTD and are encapsulated in these Notation objects. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Inherits from:
Node object
JavaScript syntax:
-
Object properties:
publicId, systemId
See also:
Doctype object, Doctype.notations[]
myNotation = new Notation()
Property
JavaScript
JScript
N
IE
Opera
DOM
Notes
publicId
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
ReadOnly
systemId
1.5 +
5.0 +
6.0 +
5.0 +
-
1+
ReadOnly
Inheritance chain: Node object
Notation.publicId (Property) The public identifier (if one was defined) for this notation. The value may be null if no identifier was defined. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myNotation.publicId
Property attributes: ReadOnly.
1545
JavaScript Programmer's Reference
Notation.systemId (Property) The system identifier (if one was defined) for this notation. The value may be null if no identifier was defined. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myNotation.systemId
Property attributes: ReadOnly.
null (Primitive value) A built-in primitive value. Availability:
ECMAScript edition – 2 JScript – 5.0 Internet Explorer – 5.0
Property/method value type:
Null primitive
JavaScript syntax:
IE
null
The null value is a primitive value that represents the null, empty, or non-existent reference. This is equivalent to the Java null data type when passing values back and forth between JavaScript and Java. If you don't have a null keyword, you may be able to simulate a null value like this: var null = (void 0); The null and undefined values are subtly different. An empty thing is not the same as a nonexistent thing. However in a browser it is difficult to distinguish between them. The null value is now provided in some browsers as a built-in keyword, but the undefined value is not. See also:
1546
Cast operator, JavaScript to Java values, LiveConnect, NaN, undefined
N – null (Type)
Cross-references: ECMA 262 edition 2 – section – 4.3.11 ECMA 262 edition 3 – section – 4.3.11 O'Reilly JavaScript Definitive Guide – page – 47
null (Type) A native built-in type. Availability:
ECMAScript edition – 2
Property/method value type:
Null primitive
The type null has exactly one value, called null. You can use this value when testing for the undefined state of variables and objects in browsers that do not support an explicit undefined value, to test for in logical expressions. See also:
Cast operator, Special type, Type
Cross-references: ECMA 262 edition 2 – section – 4.3.12 ECMA 262 edition 2 – section – 8.2 ECMA 262 edition 3 – section – 4.3.12 ECMA 262 edition 3 – section – 8.2 Wrox Instant JavaScript – page – 14
Null literal (Primitive value) A literal constant whose type is a built-in primitive value. Availability:
ECMAScript edition – 2 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0
Property/method value type:
Null primitive
JavaScript syntax:
-
null
The null literal is a value that represents the null or undefined state. It only has one value.
1547
JavaScript Programmer's Reference
Name:
null
The null value is sometimes used in place of other values. For example, in some browser-based interpreters, there is no specific value for the undefined condition. However, you can work around this by testing for null. Strictly speaking they are distinctly different values with different semantic meanings. Even so, the trick works well enough for most practical purposes. Use null in place of undefined when testing for the existence of entities. See also:
Literal, Range error, Token, undefined
Cross-references: ECMA 262 edition 2 – section – 7.7.1 ECMA 262 edition 3 – section – 7.8.1
Null statement (Definition) An empty statement consisting of a semicolon on its own. See also:
Empty statement (;), Semicolon (;)
Number (Primitive value) A built-in primitive value. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
A number value is a member of the type Number and is a direct representation of a number. It is basically a floating-point number and there is no special integer number class. Integers are simply floating-point values with a zero fractional part. Numbers can be expressed as integers or floating-point values. They can be expressed in decimal, octal, or hexadecimal notation. They can also be expressed in exponential form. Typical limits for the number type allow for very large number values. You can find out what the maximum value is by requesting the MAX_VALUE property from the built-in Number object. It will probably give you a value in the region of 1 followed by some 300 or more zeros. The smallest value is some 300 decimal places past the decimal point. Actually the limits are 1.79e308 down to 5e-324 and both can be positive or negative.
1548
N – Number (Type)
There are special constants for the values Infinity and NaN. The Infinity value can be positive or negative. The NaN value represents a quantity that is known to be numeric but is not a valid value for the implementation. It can be tested for with the isNaN() function. See also:
Cast operator, Floating constant, Infinity, isNaN(), JavaScript to Java values, Number.MAX_VALUE, Number.MIN_VALUE, Primitive value
Cross-references: ECMA 262 edition 2 – section – 4.3.19 ECMA 262 edition 3 – section – 4.3.19 Wrox Instant JavaScript – page – 14
Number (Type) A native built-in type. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
The number type defines objects that represent numbers and include the IEEE 754 NaN values in the set if the implementation is fully ECMA-compliant. The number range is huge, representing the double precision 64 bit IEEE 754 set of values. The IEEE 754 standard defines a large number of values that are considered to be not an actual number, and should be represented as NaN. Some implementations of IEEE 754 allow you to tell the difference between an overflow error and a divide by zero error. In JavaScript, all of these values are represented by a single NaN value and you cannot distinguish between them. The JavaScript NaN value is globally defined as a variable. The Number type includes the values positive and negative Infinity and, internally at least, positive and negative zero are represented as two distinct values. See also:
Cast operator, Data Type, Floating point, Fundamental data type, Hexadecimal value, IEEE 754, Infinity, Integer, NaN, Octal value, Primitive value, ToBoolean, ToInt32, ToNumber, ToObject, ToPrimitive, ToUint16, ToUint32, Type, Type conversion, valueOf()
Cross-references: ECMA 262 edition 2 – section – 4.3.19 ECMA 262 edition 2 – section – 8.5 ECMA 262 edition 3 – section – 4.3.20 ECMA 262 edition 3 – section – 8.5 O'Reilly JavaScript Definitive Guide – page – 34
1549
JavaScript Programmer's Reference
Number formats (.) (Definition) The period character is used as numeric delimiter character. ECMA describes these formats as Numeric literals. Availability:
ECMAScript edition – 2
See also:
Decimal point (.), Numeric literal
Cross-references: ECMA 262 edition 2 – section – 7.7.3 ECMA 262 edition 3 – section – 7.8.3
Number object (Object/core) An object of the class "Number". Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Netscape Enterprise Server – 2.0 Opera – 3.0
JavaScript syntax:
-
myNumber = new Number()
-
myNumber = Number
Object properties: Class constants: Object methods:
constructor, prototype MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY toExponential(), toFixed(), toLocaleString(), toPrecision(), toSource(), toString(), valueOf()
An instance of the class Number is created by using the new operator on the Number() constructor. The new object adopts the behavior of the built-in prototype object through the prototypeinheritance mechanisms. All properties and methods of the prototype are available as if they were part of the instance. A number object is a member of the type Object and is an instance of the built-in Number object.
1550
N – Number object (Object/core)
Number objects are created by cloning the built-in Number object. This is done by calling the Number constructor with the new operator being applied to an existing Number object. Thus: myNumber = new Number(1000);
A Number object can be coerced to a number value and can be used anywhere where a number value would be expected. Programmers familiar with object-oriented techniques may prefer to use the Number object while procedural language programmers may implement the same functionality with a number value instead. This is an example of the flexibility of JavaScript in its ability to accommodate a variety of users from different backgrounds. The prototype for the Number prototype object is the Object prototype object. You might want to add useful methods to the Number.prototype to output numbers in unusual formats. For example you could implement a roman numeral conversion method. Adding that to the prototype would let you output year numbers in classical formats.
Warnings: ❑
The Number object provides a collection of static constant values by way of properties belonging to the integral Number object. Because the mathematical mechanisms of any application tend to be provided by the operating system, you should find that between different browsers on any particular platform, the values that these constants yield will be very consistent.
❑
The ECMA standard lays down strict values for these properties and in general the browser manufacturers try to comply, but there is always the possibility that an implementation may use a non-compliant calculation.
❑
However, it may not be quite so reliable across platforms. You might enumerate one of these constants as you are authoring and then hard code that value into your script. When that script is executed on another platform, even in the same browser, the internal numeric support may yield a different value.
❑
You should always refer to the static constants using their symbolic names and not define them yourself, unless you are certain that the script is running on a platform that does not already define the constant value. See also:
Constant, Limits, Native object, Number.Class, Number.prototype, Object object
Property
JavaScript
JScript
N
IE
constructor prototype
1.1 + 1.1 +
1.0 + 1.0 +
3.0 + 3.0 +
3.02 + 3.02 +
Opera NES 3.0 +
2.0 +
ECMA Notes 2+ 2+
DontDelete, DontEnum
1551
JavaScript Programmer's Reference
Method
JavaScript
JScript
N
IE
toExponential() toFixed() toLocaleString() toPrecision() toSource() toString() valueOf()
1.5 + 1.5 + 1.5 + 1.5 + 1.3 + 1.1 + 1.1 +
5.5 + 5.5 + 5.5 + 5.5 + 1.0 + 3.0 +
6.0 + 6.0 + 6.0 + 6.0 + 4.06 + 3.0 + 3.0 +
5.5 + 5.5 + 5.5 + 5.5 + 3.02 + 4.0 +
Opera NES 3.0 + -
-
ECMA Notes 3+ 3+ 3+ 3+ 3+ 2+ 2+
Warning -
Cross-references: ECMA 262 edition 2 – section – 4.3.20 ECMA 262 edition 2 – section – 10.1.5 ECMA 262 edition 2 – section – 15.7 ECMA 262 edition 3 – section – 4.3.21 ECMA 262 edition 3 – section – 10.1.5 ECMA 262 edition 3 – section – 15.7 Wrox Instant JavaScript – page – 33
Number() (Constructor) A Number object constructor. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0
Property/method value type:
Number object
JavaScript syntax:
-
new Number()
-
new Number(aValue)
aValue
A value to be converted to a Number object
Argument list:
The Number() constructor is used to manufacture a new instance of the built-in Number object converting the input value to a number as it instantiates the new object. The value of the Number object when the constructor is called in a new expression is the same as value yielded by the type conversion function call. Refer to the Number() Function topic for a table of rules for converting non-number values to Number objects. The result is a Number object whose value is equivalent to the that of the passed-in argument. If the value is omitted, the Number object will assume a value of 0.
1552
N – Number() (Function)
Warnings: ❑
Note that unlike the Object() constructor, which can be called without its parentheses, calling the Number() constructor without them yields an uninitialized object. See also:
Constructor function, constructor property, Global object, new, Number.prototype, Object constant, Object()
Cross-references: ECMA 262 edition 2 – section – 15.1.3.6 ECMA 262 edition 2 – section – 15.7.1 ECMA 262 edition 2 – section – 15.7.3.1 ECMA 262 edition 3 – section – 15.7.2
Number() (Function) A Number type convertor. Availability:
ECMAScript edition – 2 JavaScript – 1.2 JScript – 1.0 Internet Explorer – 3.02 Netscape – 4.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Number()
-
Number(aValue)
aValue
A value to be converted to a number.
Argument list:
When the Number() constructor is called as a function, it will perform a type conversion. The following values are yielded as a result of calling Number() as a function: Value
Result
No value Undefined Null Boolean false Boolean true Number Non numeric string Numeric string
0 Returns NaN 0 0 1 No conversion, the input value is returned unchanged. NaN The numeric value rounded down if the number of digits exceeds the numeric accuracy specified by Number.MAX_VALUE. Table continued on following page
1553
JavaScript Programmer's Reference
Value
Result
Object
Internally, a conversion to one of the primitive types happens followed by a conversion from that type to a number. Some objects will return a number that is readily usable; others will return something that cannot be converted and NaN will result.
The result is a number value that is equivalent to the value of the passed in argument. If the argument is omitted the value 0 is returned.
Warnings: ❑
When converting strings to numbers, the number of digits in the numeric string is significant. If it exceeds the accuracy that the numeric storage can cope with, the value needs to be rounded before conversion. This is an area where the implementations are notoriously weak. MSIE apparently does a better job than Netscape. However, both are undergoing revision and its possible that the new versions of each will cope better than the older ones did. See also:
Cast operator, Constructor function, constructor property, Implicit conversion, Math.ceil(), Math.floor(), Math.round(), Number.prototype, String()
Cross-references: ECMA 262 edition 2 – section – 15.1.3.6 ECMA 262 edition 2 – section – 15.7.1 ECMA 262 edition 3 – section – 15.7.1 Wrox Instant JavaScript – page – 36
Number.Class (Property/internal) Internal property that returns an object class. Availability:
ECMAScript edition – 2
This is an internal property that describes the class that a Number object instance is a member of. The reserved words suggest that in the future, this property may be externalized. See also:
Class, Number object
Property attributes: DontEnum, Internal.
Cross-references: ECMA 262 edition 2 – section – 8.6.2 ECMA 262 edition 2 – section – 15.7.2.1 ECMA 262 edition 3 – section – 8.6.2
1554
N – Number.constructor (Property)
Number.constructor (Property) A reference to a constructor object. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0
Property/method value type:
Number object
JavaScript syntax:
-
myNumber.constructor
The initial value of the Number constructor is the built in Number object. You can use this as one way of creating number objects although it is more popular to use the new Number() technique. This property is useful if you have an object that you want to clone but you don't know what sort of object it is. Simply access the constructor belonging to the object you have a reference to. Netscape provides constructors for many objects, virtually all of them in fact, even when it is highly inappropriate to do so. MSIE is far more selective, and there are some occasions when you might wish for a constructor that is not available in MSIE. See also:
Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.prototype
Cross-references: ECMA 262 edition 2 – section – 15.7.2 ECMA 262 edition 3 – section – 15.7.2
Number.MAX_VALUE (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Number.MAX_VALUE
This is a constant value representing the largest realizable positive finite value of the Number type. The value is approximately 1.7976931348623157e+308.
1555
JavaScript Programmer's Reference
Warnings: ❑
The word approximately is used when describing the result, because the mathematical accuracy of JavaScript implementations leaves something to be desired and there are some strange artifacts in some of the calculations. See also:
Arithmetic constant, Floating point constant, Number, Number.constructor, Special number values
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.7.3.2 ECMA 262 edition 3 – section – 15.7.3.2 O'Reilly JavaScript Definitive Guide – page – 37
Number.MIN_VALUE (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Number.MIN_VALUE
This is a constant value representing the smallest realizable non-zero positive value of the number type. The resulting value is approximately 5e-324
Warnings: ❑
Although the MAX_VALUE is generally correct across implementations there are variations in the value of the MIN_VALUE constant. See also:
1556
Arithmetic constant, Floating point constant, Number, Number.constructor, Special number values
N – Number.NaN (Constant/static)
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.7.3.3 ECMA 262 edition 3 – section – 15.7.3.3 O'Reilly JavaScript Definitive Guide – page – 37
Number.NaN (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Number.NaN
This is a value representing invalid numeric values. It should be identical to the NaN value provided by the Global object in an ECMA-compliant implementation. Refer to the coverage of the NaN topic for full details. However, it is generally considered unreliable to compare against NaN values with a simple equality test. To reliably test whether a numeric value is NaN or a good numeric value, use the isNaN() function and select an appropriate action according to its result. See also:
Arithmetic constant, NaN, Number.constructor, Special number values
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.7.3.4 ECMA 262 edition 3 – section – 15.7.3.4 O'Reilly JavaScript Definitive Guide – page – 37
1557
JavaScript Programmer's Reference
Number.NEGATIVE_INFINITY (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Number.NEGATIVE_INFINITY
This is a constant representing the value negative infinity. It should be identical to a negative sign placed in front of the Infinity value provided as a property of the Global object in an ECMAcompliant implementation. Refer to the Infinity topic for further discussion.
Warnings: ❑
Netscape 2.02 does not understand what Number.NEGATIVE_INFINITY is. See also:
Arithmetic constant, Infinity, Number.constructor, Special number values
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.7.3.5 ECMA 262 edition 3 – section – 15.7.3.5 O'Reilly JavaScript Definitive Guide – page – 37 Wrox Instant JavaScript – page – 15
1558
N – Number.POSITIVE_INFINITY (Constant/static)
Number.POSITIVE_INFINITY (Constant/static) A mathematical constant value. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
Number.POSITIVE_INFINITY
This is a constant value representing positive infinity. It should be identical to the Infinity value provided as a property of the Global object in an ECMA-compliant implementation. Refer to the Infinity topic for further discussion.
Warnings: ❑
Netscape 2.02 does not understand what Number.POSITIVE_INFINITY is. See also:
Arithmetic constant, Infinity, Number.constructor, Special number values
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section – 15.7.3.6 ECMA 262 edition 3 – section – 15.7.3.6 O'Reilly JavaScript Definitive Guide – page – 37 Wrox Instant JavaScript – page – 15
1559
JavaScript Programmer's Reference
Number.prototype (Property) The prototype for the Number object that can be used to extend the interface for all Number objects. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Netscape Enterprise Server version – 2.0 Opera – 3.0
Property/method value type:
Number object
JavaScript syntax:
-
Number.prototype
-
myNumber.constructor.prototype
The prototype property refers to the built-in Number prototype object. The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.
Example code: <SCRIPT> // Define a function that extends the capabilities of the Number object function pythag(aValue1, aValue2) { return Math.sqrt((aValue1*aValue1) + (aValue2*aValue2)); } // Register the new function Number.prototype.pythag = pythag; // Create a number object and test the Number.pythag() method myNumber = new Number(); document.write(myNumber.pythag(3, 4)); document.write(" ");
See also:
Property attributes: DontDelete, DontEnum.
1560
Number object, Number(), Number(), Number.constructor, Number.toString(), Number.valueOf(), prototype property
N – Number.toExponential() (Method)
Cross-references: ECMA 262 edition 2 – section – 15.2.3.1 ECMA 262 edition 2 – section – 15.7.4 ECMA 262 edition 3 – section – 15.7.3.1
Number.toExponential() (Method) Converts the number to an exponential format representation. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myNumber.toExponential(aNumber)
Argument list:
aNumber
The number of digits after the decimal point
This method is useful for formatting number values. This is especially helpful when presenting tables of scientific data, which may require values of a wide range of magnitudes to be presented in a similar way. The argument value indicates the precision or decimal places of accuracy to the right of the decimal point character. If the argument is undefined, then as many digits as are necessary to completely distinguish the value are presented (up to the mathematical accuracy of the implementation). See also:
Number.toFixed(), Number.toPrecision(), Number.toString()
Cross-references: ECMA 262 edition 3 – section – 15.7.4.6
Number.toFixed() (Method) Converts the number to a fixed format representation. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myNumber.toFixed(aNumber)
Argument list:
aNumber
The number of digits after the decimal point
1561
JavaScript Programmer's Reference
This method is useful for truncate formatting number values. This is especially helpful when presenting tables of financial data that needs to be justified and padded to the same number of digits after the decimal point. The argument value indicates the precision or decimal places of accuracy to the right of the decimal point character. If the argument is undefined, then zero is assumed and the value will be presented as an integer. This method may be useful for performing truncations from floating point to integer value. The output of this method may also be more precise when a large number of integer digits are required to present the number. According to the ECMA standard, the alternative toString() method loses some accuracy for numbers having 19 digits for example. See also:
Number.toExponential(), Number.toPrecision(), Number.toString()
Cross-references: ECMA 262 edition 3 – section – 15.7.4.5
Number.toLocaleString() (Method) Converts a number to a string taking locale-specific settings into account. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myNumber.toLocaleString()
Locale conventions may include special formatting of numbers such as thousands separators and decimal point symbols. The number will be converted according to the rules defined by the implementation's locale setting.
Warnings: ❑
ECMA warns that the first argument of this method is reserved for future use. Beware if your implementation makes use of an argument in this method as it may be non-compliant with a later version of the ECMA standard.
Cross-references: ECMA 262 edition 3 – section – 15.7.4.3
1562
N – Number.toPrecision() (Method)
Number.toPrecision() (Method) Convert a number to a string automatically selecting fixed or exponential notation. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myNumber.toPrecision(aNumber)
Argument list:
aNumber
The number of digits after the decimal point
This method will convert a number to a string and will select either a fixed or exponential notation according to the magnitude of the value being converted. This would be useful where you have an arbitrary collection of values and don't want them presented in a ragged looking column. See also:
Number.toExponential(), Number.toFixed()
Cross-references: ECMA 262 edition 3 – section – 15.7.4.7
Number.toSource() (Method) Output a number formatted as a Number literal contained in a string. Availability:
ECMAScript edition – 3 JavaScript – 1.3 Netscape – 4.06
Property/method value type:
String primitive
JavaScript syntax:
-
myNumber.toSource()
This is an alternative way to deliver a string version of a number value. In this case, it is formatted as a Number literal and can then be used in an eval() function to assign another number. If you run the example below, it should yield this as a result: (new Number(1000))
The result of calling this method is a string version of the number formatted as a Number literal.
1563
JavaScript Programmer's Reference
Example code: // Create a number and then examine its source myNumber = new Number(1000); document.write(myNumber.toSource());
Number.toString() (Method) Return a string primitive version of an object. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Opera – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
myNumber.toString(aRadix)
Argument list:
aRadix
A radix to base the string conversion of the value on
The result of this method is a String primitive representation of the numeric value of the receiving object, rendered according to the passed-in radix value. A radix is the number of discrete values in the counting sequence before a carry over digit is generated. Thus, the radix of decimal numbers is 10. With this mechanism, you can generate values to any radix. The radix is also called the base of the number system. The radix value is in the range 2 to 36 and allows the numeric value to be reproduced in a variety of number bases. ❑
A missing radix is assumed to be base 10.
❑
Octal numbers use a radix value of 8.
❑
Hexadecimal numbers use a radix value of 16.
❑
Binary numbers use a radix value of 2.
For an example, refer to the Decimal value topic where this is used to generate a lookup table. Before the radix conversion was available, this method simply converted to a string, which most commentators considered was unnecessary since JavaScript did this naturally without any need to add special scripting support. However, now that we can convert numeric values from one base to another, this function becomes far more useful. See also:
1564
Cast operator, Decimal value, Hexadecimal value, Number.prototype, Number.toExponential(), Number.toFixed(), Octal value, toString()
N – Number.valueOf() (Method)
Cross-references: ECMA 262 edition 2 – section – 15.7.4.2 ECMA 262 edition 3 – section – 15.7.4.2
Number.valueOf() (Method) Return the primitive numeric value of the object. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0
Property/method value type:
Number primitive
JavaScript syntax:
-
myNumber.valueOf()
A Number object is converted to a simple Number primitive. You probably won't need to do this very often yourself because JavaScript is smart enough to convert Number primitives to Number objects and vice versa whenever it needs to. This is a whole lot better than having to cast data types to get expressions to work, as you would have to in other programming languages. This help makes JavaScript very accessible to non-programmers. See also:
Cast operator, Number.prototype, valueOf()
Cross-references: ECMA 262 edition 2 – section – 15.7.4.3 ECMA 262 edition 3 – section – 15.7.4.4
Numeric literal (Primitive value) A literal constant whose type is a built-in primitive value. Availability:
ECMAScript edition – 2
Property/method value type:
Number primitive
Numeric literals are constant numeric values expressed in Decimal, Hexadecimal, or Octal notation. Numeric values can be integer or floating-point. Floating-point values can be specified with exponential notation.
1565
JavaScript Programmer's Reference
Hexadecimal values must always be integers, thus: ❑
0xFF
❑
0XABCD
Octal values must always be integers, must start with a zero and contain only the characters 0–7. The standard does not mandate any particular rounding technique but recommends the use of IEEE 754 standard numeric computation. This standard has been in existence for some time now and is likely to be the foundation numeric computation standard in most platforms. See also:
Floating constant, Implicit conversion, Literal, Number formats (.)
Cross-references: ECMA 262 edition 2 – section – 7.7.3 ECMA 262 edition 3 – section – 7.8.3
Numerical limits (Definition) Limiting conditions for arithmetic values.
Refer to: Limits
1566
O Obfuscation (Advice) Needless complexity in the arrangement of tokens in a line of executable script. There are competitions on the Internet to write the most egregious and highly functional code fragment in the fewest lines of code. This is particularly easy to do in C language. Certain operators lend themselves to the construction of extremely terse code, which, although functionally very clever, is also very hard to understand when diagnosing faults or carrying out maintenance. This entry is not to recommend against the use of such operators, but to urge a word of caution on the basis that modern language parsing and execution engines may be smart enough to highly optimize the code, making any performance gains negligible anyway. These days, it is quite difficult to yield any noticeable performance gains by epitomizing the code at the source level with compiled systems. There may still be some gains to be won with interpreted code. A badly designed algorithm may continue to perform badly in an interpreter where there is a possibility it might get corrected in an optimizing compiler. The operators to be particularly cautious about are the assignment operators and the prefix/postfix operators. The ternary conditional operator is also hard to read in source and may offer little advantage over an if(… ) … else construct. These are equivalent but intent is much more obvious withthe if(… ) … else form: // Conditional ternary operator myResult = (mySwitch) ? "TRUE VALUE" : "FALSE VALUE" ; // Conditional block if(mySwitch) { myResult = "TRUE VALUE";} else { myResult = "FALSE VALUE";}
JavaScript Programmer's Reference
Where this causes particular problems is in the maintenance phase where you might perhaps be adding another line of code. In cutting and pasting an existing line, it can be easy to overlook an operator and accidentally increment something twice or assign a value inadvertently. Special care is necessary with iterators and conditional execution blocks. A particularly nasty habit is to have a condition that when true, executes one statement. This is frequently written into the source text without any enclosing braces. Those braces are important because they group the block of code into a single syntactical unit. When you later try to unpick someone else's script, the indentation may fool you into seeing several lines that appear to be conditionally executed when in fact only one is. The same applies to iterators as well. It is highly recommended that you put in the braces where they are required for multiple line conditional code and iterator blocks even when there is only one line of code being executed. This safeguards against errors when more lines are added to the conditional or iterated code block later on. This is not recommended practice: if(aCondition) someCode; while(aCondition) someCode; for( ... ) someCode; This is slightly better but requires more effort when adding lines to the code block: if(aCondition) someCode; while(aCondition) someCode; for( ... ) someCode;
This is less dangerous than having no braces but makes the line long and twice as hard to scan visually: if(Condition) { someCode }
This is fashionable, but the braces are hard to balance visually: if(aCondition) { someCode }
1568
O – Object (Definition)
This is good because it thinks ahead to the possibility of maintenance and tends towards fewer editing errors: if(aCondition) { someCode } while(aCondition) { someCode } for( ... ) { someCode }
If there is any downside to this it is that every balanced pair of braces will create a new execution context. This may slow performance, but on the other hand it can allow locally scoped variables to be created and destroyed at a level that is more granular than a function body. There is also scope for a religious debate on indentation. Three space characters works great (for me). I don't like tabs because if you move the source code to another editor, the indentation can go awry. Space characters for indentation ensure that the source code looks the same in any monospaced editing window and probably looks OK in a word processor too. See also:
Flow control, if( ... ) ..., while( ... ) ...
Object (Definition) There is a distinct difference between an object and an Object. We refer to the built-in Object class with a capitalised name. When referring generically to objects of other classes, the word object is all lower case. Therefore we can have an Object object and a String object. Native objects are built-in, host objects are also built in but created outside of the JavaScript core functionality. User-defined objects are not covered here.
1569
JavaScript Programmer's Reference
Here is a list of object classes with a note about what sort of object they are and when how they are managed: Class
Category
Description
Array Boolean Date Function Global Image Math Number Object String
Native Native Native Native Built-in Hosted Built-in Native Native Native
A collection of objects in a sequence A logical value container A date value container A function code container A container for global properties, methods, and functions Web browser image wrapper A container for math functions A numeric value A generic object A sequence of characters
Because you might refer to documents in many ways, possibly by means of object properties or as a property belonging to another window, it is not safe to assume that the document property belonging to the Global object the script is attached to is always the document object you are trying to access. Because of this, the object references in the syntax examples assume the object is being referred to via a variable called myDocument or myObject etc. For example, the value myDocument is shown being assigned as a variable from the many alternative sources from which you can obtain a document object reference.
Object (Type) A native built-in type. Availability:
ECMAScript edition – 2
An Object is an unordered collection of properties. Each property consists of a name, a value and a set of attributes. See also:
Alias, Data Type, Definition, Internal Method, Internal Property, Object object, Property, Property attribute, Type
Cross-references: ECMA 262 edition 2 – section 8.6 ECMA 262 edition 3 – section 8.6 Wrox Instant JavaScript – page 28
1570
O – Object constant (Definition)
Object constant (Definition) Constant objects. There are some constant objects defined by the standard. A host implementation may provide a few more. Here is a summary of the basic set of constant objects: ❑
Array constructor
❑
Boolean constructor
❑
Date constructor
❑
Function constructor
❑
Global object
❑
Math object
❑
Number constructor
❑
Object constructor
❑
RegExp constructor See also:
Array(), Boolean(), Closure(), Constant expression, Date(), Function(), Global object, Math object, Number(), Object literal, Object()
Cross-references: Wrox Instant JavaScript – page 28
Object inspector (Useful tip) A debugging tool for inspecting object properties and classes. Here is a small debugging utility that breaks an object down and displays some of its properties.
Example code: <SCRIPT> function object_dump(anObject) { document.write(" "); document.write(""); table_row("Item ", "Value "); if(typeof anObject != "object") {
1571
JavaScript Programmer's Reference
table_row("Value", anObject); table_row("Typeof", typeof(anObject)); } else { table_row("Value", anObject.valueOf()); table_row("String equiv", anObject.toString()); table_row("Typeof", typeof(anObject)); table_row("Class", anObject.constructor.name); table_row("Prototype", anObject.prototype); } document.write("
"); document.write(" "); } function table_row(anItem, aName) { document.write(""); document.write(""); document.write(anItem); document.write(" "); document.write(""); document.write(aName); document.write(" "); document.write(" "); } <SCRIPT> function nest(abc) { test("aa", bb, 100); } function test(aa, bb, cc, dd) { object_dump(aa); object_dump(bb); object_dump(cc); object_dump(arguments.caller.callee.name); object_dump(arguments.callee.constructor.name); } var bb; nest("aa", bb, 100); object_dump(document);
See also:
1572
Arguments object, Debugging – client side, typeof
O – Object literal (Definition)
Object literal (Definition) An object initialiser that creates the object as well. Availability:
ECMAScript edition – 3
Property/method value type:
Object object
JavaScript version 1.2 introduces Object literals. The object is created and returned by the expression. This would normally be assigned to a variable, which effectively names the object. It isn't the object class but it can be copied. Its class is still "Object". Object literals can be nested so that the properties of the topmost object can in fact be object literals themselves. The values assigned to the properties as the object is created can be derived by evaluating a JavaScript expression. You can add as many properties as you care to but you must be careful to keep the nesting properly balanced. The result is an object with the properties containing the values described in the literal expression.
Example code: // Create a simple object literal var simple = { prop:100 }; // Create a nested object literal var nested = { reference: { prop:100 } }; // Create a nested object literal with expression derived value var evaluated = { reference: { prop:(Math.random()*100) } };
See also:
Object constant, Object.constructor
Cross-references: ECMA 262 edition 3 – section – 11.1.5 O'Reilly JavaScript Definitive Guide – page – 45
Object model (Definition) There are several different object models that are realized in JavaScript implementations. In the Netscape and MSIE web browsers, the object models are provided as representations of the document, the browser, event capturing mechanisms, and the style sheet. In addition, some implementations model the environs, the operating system, and the file system. Each of these object models interacts with the others and is a way of representing the tangible real-world objects.
1573
JavaScript Programmer's Reference
Although these are generally arranged in a tree-like structure, there are many short cut references that mean you can refer to the same object in a variety of ways. For example the Netscape JavaPackage object can be referred to with the following properties in a Netscape browser: ❑
Netscape
❑
Packages.netscape
❑
window.Packages.netscape
Each one refers to an identical object but from the script writer’s point of view, some time can be saved by using the short cuts. Scripts also appear simpler to read. However, the downside is that the object model hierarchy becomes confusing unless you know about the short-cuts. These shortcuts provided for 'so-called' convenience may in fact be exactly the opposite if they are only available on one platform. Using them immediately renders your script non-portable.
Object object (Object/core) An object of the class "Object". Availability:
JavaScript syntax:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Netscape Enterprise Server 2.0 Opera 3.0 myObject = new Object() -
Object properties: Object methods:
myObject = Object
__parent__, __proto__, constructor, name, prototype assign(), eval(), hasOwnProperty(), isPrototypeOf(), propertyIsEnumerable(), toLocaleString(), toSource(), toString(), unwatch(), valueOf(), watch()
An instance of the class "Object" is created by using the new operator on the Object() constructor. The new object adopts the behavior of the built-in prototype object through the prototype-inheritance mechanisms. All properties and methods of the prototype are available as if they were part of the instance. An Object is a member of the type Object. It is an unordered collection of properties, each of which may contain a primitive value, another object, or a function. The constructor is invoked by the new operator or by calling it as a Constructor function. For example: new String("Some Text");
1574
O – Object object (Object/core)
This will create a new object of the String type. You can invoke the constructor without the new operator but the consequences will depend on the constructor as to what it will yield as a result. In the case of the String data type, the constructor could be invoked like this: String("Some Text");
However, you would get a primitive string as a result from this and not a String object. JavaScript is somewhat forgiving and you may not notice this happening until later on when it becomes important that you have a String object and not a simple string. Because this object is the topmost parent object in the prototype inheritance hierarchy, all other object classes inherit its methods and properties. However, in some cases they will get overridden or nulled out. DOM level 2 adds the following properties: contentDocument Although JavaScript is object-based, it does not support true object-oriented classes such as the ones you find in C++, Smalltalk, Java or Objective C. Instead, it provides Constructor mechanisms, which create objects by allocating space for them in memory and assigning initial values to their properties. All functions, including constructors are themselves objects; however, not all objects are constructors. Each constructor has a Prototype property that is used to facilitate inheritance based on the prototype. It also provides for shared properties, which is similar to but not the same as the Class properties that you find in true object-oriented languages. Externally, the objects in JavaScript exhibit most of the attributes of a class based object oriented system and some commentators argue that this qualifies JavaScript as being a genuine object oriented system. However I think the following points declassify it as a truly object oriented system, meaning that it is an "object like" system: ❑
Global variables and the scope chain mechanism
❑
Prototype based inheritance
❑
Creation of multiple objects and calling them within a single script
❑
Object data is not truly private
It’s a close enough call that JavaScript 2.0 may well move it into the class-based object-oriented category at which time the prototype inheritance would be replaced with super-class/sub-class mechanisms and the arguments become null and void.
Warnings: ❑
Be very careful not to confuse this generic top-level core object with the object that MSIE instantiates to represent an tag. MSIE creates OBJECT objects for that purpose but also supports Object objects. For this reason, it may be the case that interpreters cannot become case-insensitive when matching class names. If they did, then it would be impossible to distinguish between Object and OBJECT class names.
1575
JavaScript Programmer's Reference
See also:
Aggregate type, Array object, Boolean object, Date object, delete, Function object, Math object, Native object, Number object, Object, OBJECT object, Object(), Object(), Object.Class, Object.prototype, String object, userDefined object
Property
JavaScript
JScript
N
IE
Opera
NES
ECMA Notes
__parent__
1.2 +
-
4.0 +
-
-
-
-
-
__proto__
1.2 +
-
4.0 +
-
-
-
-
-
constructor
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
-
2+
-
name
-
5.5 +
-
5.5 +
-
-
-
-
prototype
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
-
2+
Warning, ReadOnly, DontDelete, DontEnum
Method
JavaScript
JScript
N
IE
Opera
NES
ECMA Notes
assign()
1.1 +
-
3.0 +
-
-
-
-
Warning, Deprecated
eval()
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
2.0 +
-
Warning, Deprecated
hasOwn Property() isPrototype Of() propertyIs Enumerable() toLocale String() toSource()
1.5 +
5.5 +
6.0 +
5.5 +
-
-
3+
-
1.5 +
5.5 +
6.0 +
5.5 +
-
-
3+
-
1.5 +
5.5 +
6.0 +
5.5 +
-
-
3+
-
1.5 +
5.5 +
6.0 +
5.5 +
-
-
3+
Warning
1.3 +
3.0 +
4.06 +
4.0 +
-
-
-
Warning
toString()
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
-
2+
-
unwatch()
1.2 +
-
4.0 +
-
-
3.0 +
-
Warning
valueOf()
1.1 +
3.0 +
3.0 +
4.0 +
3.0 +
2.0 +
2+
-
watch()
1.2 +
-
4.0 +
-
-
3.0 +
-
Warning
Cross-references: ECMA 262 edition 2 – section 4.2.1 ECMA 262 edition 2 – section 4.3.3 ECMA 262 edition 2 – section 10.1.5 ECMA 262 edition 2 – section 15.2 ECMA 262 edition 3 – section 4.2.1 ECMA 262 edition 3 – section 4.3.3
1576
O – Object() (Constructor)
ECMA 262 edition 3 – section 10.1.5 ECMA 262 edition 3 – section 15.2 O'Reilly JavaScript Definitive Guide – page 44 Wrox Instant JavaScript – page 28
Object() (Constructor) An Object object constructor. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Netscape Enterprise Server 2.0 Opera 3.0
Property/method value type:
Object object
JavaScript syntax:
Argument list:
-
new Object
-
new Object()
-
new Object(aValue)
aValue
An initial value for the new object
When Object is called as part of a new expression, it is a constructor that may create an object instance. There are limitations what is sensible for the new operator to be able to do with the Object constructor. Since the Object is considered to be the highest ancestor of all objects in the prototype inheritance chain, you cannot logically have more than one Object object. Passing other native objects to the Object Constructor implies a type casting from their native object type to the Object type. That's not logical either. The main use of the Object Constructor then is to manufacturer object instantiations from non-object data types. The table summarizes the resulting values from using the Object() constructor with the new operator. Value
Result
No argument
Creates a new empty object
null
Creates a new empty object
undefined
Creates a new empty object
Boolean
Create a new boolean object whose default value is the input value
Number
Create a new number object whose default value is the input value
String
Create a new string object whose default value is the input value
Native object
Return the native object itself
Host object
Host implementation dependant behavior. Objects are cloned if necessary but some may not be
1577
JavaScript Programmer's Reference
Unless you assign the result of the new operation, an object will simply consume memory. You need to store a reference to it at the time it is instantiated. You can do this by assigning it to a variable or a property of another object, passing it in to a function and making sure it gets retained in there, or storing it as an element in an array.
Warnings: ❑
You can refer to objects without the parentheses but then you are not referring to a constructor function but to the object itself. The behavior varies between browsers and depends on the kind of object being instantiated and probably depends on whether it is a wrapper for a primitive data type or a more complex aggregated type.
❑
These all appear to create the same kind of object in both MSIE and Netscape myObject = Object(); myNewObject = new Object(); myOtherObject = new Object; These do not: myBoolean = Boolean(); myNewBoolean = new Boolean(); myOtherBoolean = new Boolean;
❑
In the case of the Boolean, Number, and String object types, only the first form will initialize the new object with a value. Placing the result of these examples in document.write() statements illustrates the behavior. You may want to examine the objects returned in more detail by developing an object inspector script. See also:
Boolean(), Constructor function, constructor property, Garbage collection, Global object, Memory leak, new, Number(), Object constant, Object object, Object.prototype, Reference counting, String()
Cross-references: ECMA 262 edition 2 – section 15.1.1 ECMA 262 edition 2 – section 15.1.3.1 ECMA 262 edition 2 – section 15.2.2.2 ECMA 262 edition 3 – section 15.2.2
1578
O – Object() (Function)
Object() (Function) An Object object constructor. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0
Property/method value type:
An object of a type that depends on the passed in argument
JavaScript syntax:
-
Object()
-
Object(aValue)
aValue
A value to be stored in the new object.
Argument list:
The Object Constructor can be called as a function. When this happens, the value passed in undergoes a type conversion. In an ECMA-compliant implementation, the Object constructor function uses the ToObject conversion. However it handles input values undefined and null as special cases and creates a new object as if the constructor had been used with the new operator. The table summarizes the results based on the input value data types. Value
Result
No argument null
Creates a new empty object as if new Object() had been called. Creates a new empty object as if new Object(null) had been called. Creates a new empty object as if new Object(undefined) had been called. Create a new boolean object whose default value is the input value. Create a new number object whose default value is the input value. Create a new string object whose default value is the input value. No conversion, the input value is returned unchanged.
undefined Boolean Number String Object
See also:
Cast operator, Constructor function, constructor property, Implicit conversion, Object object
Cross-references: ECMA 262 edition 2 – section 15.1.1 ECMA 262 edition 2 – section 15.1.3.1 ECMA 262 edition 2 – section 15.2.2.2 ECMA 262 edition 3 – section 15.2
1579
JavaScript Programmer's Reference
Object.__parent__ (Property) A special property in which to access the scope chain during function execution. Availability:
JavaScript – 1.2 Netscape – 4.0
Property/method value type:
ScopeChain object
JavaScript syntax:
N
See also:
Lexical scoping, __parent__
myObject.__parent__
Object.__proto__ (Property) A special property in which to access the prototype inheritance chain during construction. Availability:
JavaScript – 1.2 Netscape – 4.0
Property/method value type:
Function object
JavaScript syntax:
N
See also:
Lexical scoping, Prototype Based Inheritance, Prototype chain, __proto__
myObject.__proto__
Object.assign() (Method) A deprecated mechanism for intercepting messages sent to objects.
Availability:
JavaScript – 1.1 Netscape – 3.0 Deprecated
JavaScript syntax:
N
myObject.assign()
Warnings: ❑
This method is deprecated in favor of the Object.watch() and Object.unwatch() methods. See also:
1580
Object.unwatch(), Object.watch()
O – Object.Class (Property/internal)
Object.Class (Property/internal) Internal property that returns an object class. Availability:
ECMAScript edition – 2
This is an internal property that describes the class that an Object object instance is a member of. The reserved words suggest that in the future, this property may be externalized. See also:
Class, Object object
Property attributes: DontEnum, Internal.
Cross-references: ECMA 262 edition 2 – section – 8.6.2 ECMA 262 edition 2 – section – 15.2.2.1 ECMA 262 edition 3 – section – 8.6.2
Object.constructor (Property) A reference to a constructor object. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0 Opera browser – 3.0
Property/method value type:
Object object
JavaScript syntax:
-
myObject.constructor
The initial value of the Object.prototype.constructor is the built-in Object constructor. You can use this as one way of creating objects although it is more popular to use the new Object() technique. This property is useful if you have an object that you want to clone but you don't know what sort of object it is. Simply access the constructor belonging to the object you have a reference to. Netscape provides constructors for many objects, virtually all of them in fact, even when it is highly inappropriate to do so. MSIE is far more selective and there are some occasions when you might wish for a constructor that MSIE does not make available. See also:
Object literal, Object.prototype
1581
JavaScript Programmer's Reference
Cross-references: ECMA 262 edition 2 – section – 15.2.4.1 ECMA 262 edition 3 – section – 15.2.2
Object.eval() (Method) Evaluate the JavaScript source text passed in a string argument. Availability:
JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Netscape Enterprise Server version – 2.0 Opera browser – 3.0 Deprecated
Property/method value type:
Function result
JavaScript syntax:
-
myObject.eval()
Warnings: ❑
This is now deprecated and may even be unavailable in recent versions of Netscape and JScript. You should use the eval() function available from the global object. See also:
eval()
Object.hasOwnProperty() (Method) A method that can be used to test whether a property exists and belongs to the receiving object. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
myObject.hasOwnProperty(aName)
Argument list:
aName
The name of a property to test for
For this method to yield a Boolean true value, the property named in the argument must exist and must belong to the receiving object. If the property is inherited from a prototype or earlier ancestor then this method returns false.
1582
O – Object.isPrototypeOf() (Method)
This method would be useful if it could test for the existence of a property in the inheritance chain. There is an internal HasProperty() method but the ECMA standard indicate that it is not exposed to the script interface. See also:
HasProperty()
Cross-references: ECMA 262 edition 3 – section – 15.2.4.5
Object.isPrototypeOf() (Method) A test for the relationship between two objects to ascertain direct parentage. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
myObject.isPrototypeOf(anObject)
Argument list:
anObject
The object whose prototype is to be tested
The receiving object is tested for identity against the object referred to by the prototype property of the object passed as an argument. If the object in the argument is a direct child object through the prototype chain, then this method returns a true value. See also:
HasInstance()
Cross-references: ECMA 262 edition 3 – section – 15.2.4.6
Object.name (Property) This corresponds to the NAME attribute of the tag that creates the object. Availability:
JScript – 5.5 Internet Explorer – 5.5
Property/method value type:
String primitive
JavaScript syntax:
IE
myObject.name
1583
JavaScript Programmer's Reference
Objects are identified either by the NAME="… " HTML tag attribute or by the ID="… " HTML tag attribute. Netscape shows a marginal preference for the name property while MSIE seems slightly better disposed towards the ID property. However in many cases, both browsers support either technique and in some cases will locate items named with either tag as if they existed in a single namespace. See also:
NAME="..."
Object.propertyIsEnumerable() (Method) A test for whether a property has the don't enumerate flag set or not. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
Boolean primitive
JavaScript syntax:
-
myObject.propertyIsEnumerable(aName)
Argument list:
aName
The name of the object property to test
If the receiving object has a member property of the name that is passed in the argument, and if the DontEnum attribute of that property is false, then this method returns the Boolean true value.
Cross-references: ECMA 262 edition 3 – section 15.2.4.7
Object.prototype (Property) The prototype for the Object object, which can be used to extend the interface for all Object objects. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Opera browser – 3.0
Property/method value type:
Object object
JavaScript syntax:
-
Object.prototype myObject.constructor.prototype
The initial value of the prototype property of an Object object is the built in Object prototype object.
1584
O – Object.prototype (Property)
Object objects inherit the following properties from the Object.prototype: ❑
Object.constructor
❑
Object.prototype
Object objects inherit the following methods from their prototype: ❑
Object.toString()
❑
Object.valueOf()
The prototype property for the Object prototype object is null. The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.
Warnings: ❑
This is not supported on the WebTV platform.
Example code: <SCRIPT> // Define a function that extends the output capabilities of Object objects function init() { this.width = 100; this.height = 200; this.depth = 300; return ""; } // Register the new function Object.prototype.init = init; // Create a new object myObject = new Object(); myObject.init(); document.write(myObject.width + " "); document.write(myObject.height + " "); document.write(myObject.depth + " ");
See also:
Arguments object, Function.arguments[], JellyScript, Object object, Object(), Object.constructor, Object.toString(), Object.valueOf(), prototype property
1585
JavaScript Programmer's Reference
Property attributes: ReadOnly, DontDelete, DontEnum.
Cross-references: ECMA 262 edition 2 – section 15.2.3.1 ECMA 262 edition 2 – section 15.2.4 ECMA 262 edition 3 – section 15.2.3.1
Object.toLocaleString() (Method) Returns a string primitive version of the object taking the present locale into account during the translation. Availability:
ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myObject.toLocaleString()
The locale context supplies some special conversion rules for strings. Depending on the locale, this might include special characters or a means of using double byte characters. It may also affect the direction of the text, for certain Asian locales for example.
Warnings: ❑
The ECMA standard reserves the first argument of this method for future use. It does not specify what that is but warns against implementations extending the syntax to include its use.
Cross-references: ECMA 262 edition 3 – section – 15.2.4.3
Object.toSource() (Method) Output a string describing the object contents. Availability:
JavaScript – 1.3 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.06
Property/method value type:
String primitive
JavaScript syntax:
-
1586
myObject.toSource()
O – Object.toString() (Method)
This is an alternative way to deliver a string version of an object's internal values. In this case, it is formatted as an Object literal and can then be used in an eval() function to assign another object. The exact format of what you see depends on the object being examined. The result of calling this method is string version of the object formatted as an Object literal.
Warnings: ❑
Note that this is not available in the MSIE browser but can be useful when constructing an Object inspector for use in Netscape.
Object.toString() (Method) Return a string primitive version of an object. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Opera browser – 3.0
Property/method value type:
String primitive
JavaScript syntax:
-
myObject.toString()
When the toString() method of an Object.prototype is invoked, the class name of the object is returned as a string. The result of calling this method will be the string: [object "Object"] See also:
Cast operator, Object.prototype, toString()
Cross-references: ECMA 262 edition 2 – section – 15.2.4.2 ECMA 262 edition 3 – section – 15.2.4.2
1587
JavaScript Programmer's Reference
Object.unwatch() (Method) A method to disable a watch that was set up on a property change. Availability:
JavaScript – 1.2 Netscape – 4.0 Netscape Enterprise Server – 3.0
JavaScript syntax:
N
myObject.unwatch()
This is inherited by most object classes in Netscape.
Warnings: ❑
Because of the scoping rules, you cannot actually examine the value of the variable that has changed since the event handler is running in a completely different scope chain.
Example code: <SCRIPT> function watchFunct() { alert("Variable changed"); } watch("myVariable", watchFunct) myVariable = 100; myVariable = 200; unwatch("myVariable") myVariable = 300;
See also:
Object.assign(), Object.watch()
Object.valueOf() (Method) The primitive numeric value of the object. Availability:
ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Netscape Enterprise Server – 2.0 Opera – 3.0
Property/method value type:
Depends on the object value
JavaScript syntax:
-
1588
myObject.valueOf()
O – Object.watch() (Method)
As a general rule, the valueOf() method for an object simply returns the this property of the object itself. However, the object may be a wrapper for a host object some kind. It may therefore have been created by invoking the Object constructor. In that case, the host object should be returned in an ECMA-compliant implementation. Implementations may choose to return the this property of an object or some other value if they choose. The result of this method will be implementation-and object-dependant. The native core objects are well defined and will return predictable value types. Generally these will be defined by ECMA or W3C standards. It is up to the hosting environment to provide the valueOf() interface to its own suite of objects. See also:
Cast operator, Object.prototype, valueOf()
Cross-references: ECMA 262 edition 2 – section – 15.2.2.1 ECMA 262 edition 2 – section – 15.2.4.3 ECMA 262 edition 3 – section – 15.2.4.4
Object.watch() (Method) A means of establishing a call back when a property value changes. Availability:
JavaScript – 1.2 Netscape – 4.0 Netscape Enterprise Server version – 3.0
JavaScript syntax:
N
myObject.watch()
This is inherited by most object classes in Netscape.
Warnings: ❑
Because of the scoping rules, you cannot actually examine the value of the variable that has changed since the event handler is running in a completely different scope chain.
Example code: <SCRIPT> document.watch("myVariable", alert("Watch point triggered")) document.myVariable = 100;
See also:
Object.assign(), Object.unwatch(), unwatch(), watch()
1589
JavaScript Programmer's Reference
Object property delimiter (.) (Delimiter) A token to delimit object properties from their object. Availability:
JavaScript syntax: Argument list:
ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.0 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera browser – 3.0 -
myObject.aProperty
-
myObject.aProperty.aProperty
aProperty
The identifier name of property to be accessed
The dot delimits properties and objects. It can find properties of properties of objects too. The associativity is left to right. Refer to the Operator Precedence topic for details of execution order. You can also access the property values as if the object were an array. This: anObject.aProperty is equivalent to: anObject["aProperty"] The result will be the value of the property when it is an RValue or a reference to the property when it is an LValue. See also:
Associativity, Decimal point (.), Operator Precedence, Postfix operator
Cross-references: ECMA 262 edition 2 – section 8.6 ECMA 262 edition 2 – section 11.2 ECMA 262 edition 3 – section 8.6 ECMA 262 edition 3 – section 11.2.1 Wrox Instant JavaScript – page 28
1590
O – OBJECT object (Object/HTML)
OBJECT object (Object/HTML) This is an object that encapsulates an ActiveX plugin. Do not confuse it with the Object object that is the super-class of all objects in JavaScript. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Inherits from:
Element object
JavaScript syntax:
IE
myOBJECT = myDocument.all.anElementID
IE
myOBJECT = myDocument.all.tags("OBJECT")[anIndex]
IE
myOBJECT = myDocument.all[aName]
-
myOBJECT = myDocument.applets[anIndex]
-
myOBJECT = myDocument.getElementById(anElementID)
-
myOBJECT = myDocument.getElementsByName (aName)[anIndex] myOBJECT = myDocument.getElementsByTagName ("OBJECT")[anIndex]
HTML syntax: Argument list:
... anIndex
A reference to an element in a collection
aName
An associative array reference
anElementID Object properties:
Event handlers:
The ID value of an Element object accessKey, align, altHtml, archive, border, classid, code, codeBase, codeType, data, dataFld, dataSrc, declare, form, height, hspace, name, object, readyState, standby, tabIndex, type, useMap, vspace, width onAfterUpdate, onBeforeUpdate, onBlur, onClick, onDataAvailable, onDataSetChanged, onDataSetComplete, onDblClick, onDragStart, onError, onErrorUpdate, onFilterChange, onFocus, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onReadyStateChange, onRowEnter, onRowExit, onSelectStart
This is an object representing an HTML tag. The tag is a block-level tag. That means that it forces a line break before and after itself. This object is specific to the MSIE browser when it runs on the Windows operating system. No other browser supports ActiveX as well as MSIE and no other operating system properly or completely supports the ActiveX infrastructure. The events handled, and the properties and the methods of this object will depend on the kind of ActiveX object that is created. The DOM level 1 specification refers to this as an ObjectElement object.
1591
JavaScript Programmer's Reference
Warnings: ❑
Be very careful not to confuse this object with the generic top level core Object object that is the super-class of all objects in the interpreter.
❑
This is the object that MSIE instantiates to represent an tag. MSIE creates OBJECT objects for that purpose but also supports Object objects. For this reason, it may be the case that interpreters cannot become case insensitive when matching class names. If they did, then it would be impossible to distinguish between Object and OBJECT class names.
❑
Creating an OBJECT class when an Object class already exists must have been a moment of insanity in an otherwise mostly excellent browser implementation project. See also:
ActiveXObject object, Document.applets[], Element object, Input.accessKey, Object object
Property
JavaScript
JScript
N
IE
Opera
DOM
HTML
Notes
accessKey
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
Warning
align
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
altHtml
-
3.0 +
-
4.0 +
-
-
-
-
archive
1.5 +
-
6.0 +
-
-
1+
-
Deprecated
border
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
classid
-
3.0 +
-
4.0 +
-
-
-
ReadOnly
code
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
codeBase
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
codeType
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
data
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
ReadOnly
dataFld
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
Warning
dataSrc
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
Warning
declare
1.5 +
-
6.0 +
-
-
1+
-
-
form
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
ReadOnly
height
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
hspace
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
name
-
5.5 +
-
5.5 +
-
-
-
-
object
-
3.0 +
-
4.0 +
-
-
-
ReadOnly
readyState
-
3.0 +
-
4.0 +
-
-
-
ReadOnly
standby
1.5 +
-
6.0 +
-
-
1+
-
-
tabIndex
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
type
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
useMap
1.5 +
-
6.0 +
-
-
1+
-
-
vspace
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
width
1.5 +
3.0 +
6.0 +
4.0 +
-
1+
-
-
1592
O – OBJECT object (Object/HTML)
Event name
JavaScript
JScript
N
IE
Opera DOM
HTML
Notes
onAfterUpdate
-
3.0 +
-
4.0 +
-
-
-
-
onBeforeUpdate
-
3.0 +
-
4.0 +
-
-
-
-
onBlur
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
-
Warning
onClick
1.5+
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onDataAvailable
-
3.0 +
-
4.0 +
-
-
-
-
onDataSetChanged
-
3.0 +
-
4.0 +
-
-
-
-
onDataSetComplete
-
3.0 +
-
4.0 +
-
-
-
-
onDblClick
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onDragStart
-
3.0 +
-
4.0 +
-
-
-
-
onError
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
-
Warning
onErrorUpdate
-
3.0 +
-
4.0 +
-
-
-
-
onFilterChange
-
3.0 +
-
4.0 +
-
-
-
-
onFocus
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
-
Warning
onHelp
-
3.0 +
-
4.0 +
-
-
-
Warning
onKeyDown
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onKeyPress
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onKeyUp
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseDown
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseMove
1.5 +
3.0 +
6.0 +
4.0 +
-
-
4.0 +
Warning
onMouseOut
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseOver
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onMouseUp
1.5 +
3.0 +
6.0 +
4.0 +
3.0 +
-
4.0 +
Warning
onReadyStateChange
-
3.0 +
-
4.0 +
-
-
-
-
onRowEnter
-
3.0 +
-
4.0 +
-
-
-
-
onRowExit
-
3.0 +
-
4.0 +
-
-
-
-
onSelectStart
-
3.0 +
-
4.0 +
-
-
-
-
Inheritance chain: Element object, Node object
Web-references: http://www.w3.org/pub/WWW/TR/WD-object.htm
1593
JavaScript Programmer's Reference
OBJECT.align (Property) An alignment control for an tag's position with respect to its parent object. Availability:
DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0
Property/method value type:
String primitive
JavaScript syntax:
-
myOBJECT.align
The alignment of the ActiveX OBJECT object with respect to its containing parent object is defined in this property. The expected and widely available set of alignment specifiers are available: ❑
absbottom
❑
absmiddle
❑
baseline
❑
bottom
❑
center
❑
left
❑
middle
❑
right
❑
texttop
❑
top
OBJECT.altHtml (Property) A block of alternative HTML to be used if the tag fails to load its plugin correctly. Availability:
JScript – 3.0 Internet Explorer – 4.0
Property/method value type:
String primitive
JavaScript syntax:
IE
myOBJECT.altHtml
The alternative HTML is used in case the base tag experiences a problem when loading or the browser cannot use ActiveX objects as embeds. Of course if this property is accessible from the OBJECT object during scripting, the browser must have parsed the tag, although it may still have had problems with the component. This HTML is enclosed between the and tags in the HTML document source.
1594
O – OBJECT.archive (Property)
Certain tags are likely to be omitted from the altHTML property value. blocks contain tags for passing values to the embedded ActiveX component. Clearly you won't want these appearing in the display if the component fails to load. The tags are considered integral to the and it’s smart enough to disregard them as it constructs its alternative HTML block. Browsers that cannot understand and render