About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets







[Contents] [Previous] [Next] [Last]


Chapter 5

Objects

This section describes the following new objects and changes to existing objects:

In addition, objects can now be creating using literal notation.

Creating Objects With Literal Notation

In addition to creating an object using its constructor function, you can create it using literal notation.

Syntax

objectName = {property1:value1, property2:value2,..., propertyn:valuen}

Properties

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.

Description

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.

Example

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}}

arguments

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:

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:

534
2
99

534 is the actual parameter to b, so it is the value of arguments.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.

Number

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

screen

Client-side object. Contains information about the display screen resolution and colors.

Syntax

screen.propertyName

Parameters

propertyName is one of the properties listed below.

Property of

None

Properties

Property Description
availHeight
Specifies the height of the screen, in pixels, minus permanent or semi-permanent user interface features displayed by the operating system, such as the Taskbar on Windows.
availWidth
Specifies the width of the screen, in pixels, minus permanent or semi-permanent user interface features displayed by the operating system, such as the Taskbar on Windows.
height
Specifies the height of the screen in pixels.
width
Specifies the width of the screen in pixels.
colorDepth
Specifies the number of colors possible to display. The number of colors is found using the color palette if one is available, or using the pixel depth.
pixelDepth
Specifies the number of bits per pixel in the display.

Methods and Properties

None


[Contents] [Previous] [Next] [Last]