[Contents]
[Previous] [Next] [Last]zo
This section describes the following new objects and changes to existing objects:
arguments
event
Array
(links to a different page)
Number
the
regular expression object
RegExp
screen
String
(links to a different page)
In addition, objects can now be creating using literal notation.
In addition to creating an object using its constructor function, you can create it using literal notation.
objectName = {property1:value1, property2:value2,..., propertyn:valuen}
objectName
is the name of the new object
propertyn is an identifier; either a name, a number,
or a string literal.
valuen is an expression whose value is assigned to
the propertyn.
If an object is created using literal notation in a top-level script, JavaScript interprets the object each time it evaluates the expression containing the object literal. In addition, a literal used in a function is created each time the function is called.
Assume you have the following statement:if (cond) x = {hi:"there"}
In this case, JavaScript makes the literal object and assigns it to the variable x
if and only if the expression cond is true.
The following example creates myHonda with three properties. Note that the
engine property is also an object with its own properties.
myHonda = {color:"red",wheels:4,engine:{cylinders:4,size:2.2}}
Core object; property of function. The arguments array object
provides information about a function at the time the function is invoked. In previous
JavaScript versions, arguments provided a list of indexed elements and a
length property. In JavaScript 1.2, arguments includes these additional
properties:
arguments
array. arguments
array. caller--a property whose value is the arguments array of the
outer function. If there is no outer function, the value is undefined. callee--a property whose value is the function reference. For example, the following script demonstrates several of the arguments
properties:
<SCRIPT LANGUAGE="JavaScript1.2">
function b(z) {
document.write(arguments.z + "<BR>")
document.write (arguments.caller.x + "<BR>")
return 99
}
function a(x, y) {
return b(534)
}
document.write (a(2,3) + "<BR>")
</SCRIPT>
This writes:
534arguments.z
2 is a's actual x parameter, so (viewed within b) it is the value
of arguments.caller.x.
99 is what a(2,3) returns.
Core object. Number(x) now produces NaN rather than an error if x is a
string that does not contain a well-formed numeric literal. For example,
x=Number("three");
document.write(x + "<BR>");
prints NaN
Client-side object. Contains information about the display screen resolution and colors.
screen.propertyName
propertyName
is one of the properties listed below.
None
None
[Contents]
[Previous] [Next] [Last]Last Updated: 10/22/97 11:48:05
Copyright © 1997 Netscape Communications Corporation