[Previous] [Next] [TOC] 


Functions

This section describes the following new functions and features of functions:

Nesting Functions Within Functions

You can nest a function within a function. The nested function can use the arguments and variables of the outer function. The outer function cannot use the arguments and variables of the nested function. The nested function is unknown outside of the outer function and cannot be called independently.


Function Constructor

You can now create a function using a constructor function. For example:

var f = new Function('x', 'y', "return x * y")

Number

Core function. Converts the specified object to a number.

Syntax

Number(x)

Parameter

x is any object.

Description

When the object is a Date object, Number returns a value in milliseconds measured from 01 January, 1970 UTC (GMT), positive after this date, negative before.

Example

The following example converts the Date object to a numerical value:

<SCRIPT>
d = new Date ("December 17, 1995 03:24:00"); 
document.write (Number(d) + "<BR>");
</SCRIPT>

This prints "819199440000."

String

Core function. Converts the specified object to a string.

Syntax

String(x)

Parameter

x is any object.

Description

When the object is a Date object, String returns a string representation of the date. Its format is: Thu Aug 18 04:37:43 Pacific Daylight Time 1983.

Example

The following example converts the Date object to a readable string.

<SCRIPT>
D = new Date (430054663215); 
document.write (String(D) +" <BR>");
</SCRIPT>

This prints "Thu Aug 18 04:37:43 Pacific Daylight Time 1983."


[Previous] [Next] [TOC] 



Copyright © 1997 Netscape Communications Corporation