Chapter 3 DynaScript Predefined Objects
Enables the creation of functions.
Standard: ECMAScript
To use a Function property:
Function.propertyName
To use a Function method:
Function.MethodName( parameter )
The function constructor can be used to create a function on the fly:
funcName = new Function( [[parameter1 [, parameter2...]], body] );
The function keyword can also be used to create a function, in which case the function is not created until it has been called from somewhere else in the script:
function funcName ( [parameter1 [, parameter2...]], ) {
body
}
This example creates two Function objects called square and square1 and executes them:
<!--SCRIPT // function created with a constructor square = new Function( "number", "return number * number;" ); // function created with the keyword function square1 ( number) { return number * number } document.writeln( square(5) ); document.writeln( square1(5) ); -->
Function.length
This property is read-only.
Returns the number of parameters required by the Function.
Integer
This example returns the number of parameters required by the function:
<!--SCRIPT myFunc = new Function( "x","y", "return x * y;" ); document.WriteLn( "The function myFunc takes " + myFunc.length + " parameters." ); document.WriteLn( myFunc(5, 6) ); -->
Function.toString( )
Returns the body of the function as a string.
String
This example displays the body of the function:
<!--SCRIPT myFunc = new Function( "x","y", "return x * y;" ); document.writeln( myFunc(5, 6) ); document.WriteLn( myFunc.toString() ); -->
Copyright © 2001 Sybase, Inc. All rights reserved. |
![]() |