Bookshelf Home | Contents | Index | PDF |
Siebel eScript Language Reference > Siebel eScript Commands > Function ObjectsA Function object holds the definition of a function defined in eScript. Note that in eScript, procedures are functions. Syntax Afunction funcName( [arg1 [, ..., argn]] ) Syntax Bvar funcName = new Function([arg1 [, ..., argn,]] body ); ReturnsWhatever its code is set up to return. For more information, read return Statement. UsageSyntax A is the standard method for defining a function. Syntax B is an alternative way to create a function and is used to create Function objects explicitly. Note the difference in case of the keyword Function between Syntax A and Syntax B. Function objects created with Syntax B (that is, the Function constructor) are evaluated each time they are used. This is less efficient than Syntax A—declaring a function and calling it within your code—because declared functions are compiled instead of interpreted. ExampleThe following fragment of code illustrates creating a function AddTwoNumbers using a declaration: function AddTwoNumbers (a, b) The following fragment illustrates creating the same function using the Function constructor: AddTwoNumbers = new Function ("a", "b", "return (a + b)"); The difference between the two is that when AddTwoNumbers is created using a declaration, AddTwoNumbers is the name of a function, whereas when AddTwoNumbers is created using the Function constructor, AddTwoNumbers is the name of a variable whose current value is a reference to the function created using the Function constructor. length PropertyThe length property returns the number of parameters expected by the function. SyntaxReturnsThe number of parameters expected by funcName. return StatementThe return statement passes a value back to the function that called it. SyntaxUsageThe return statement passes a value back to the function that called it. Any code in a function following the execution of a return statement is not executed. ExampleThis function returns a value equal to the number passed to it multiplied by 2 and divided by 5. function DoubleAndDivideBy5(a) Here is an example of a script using the preceding function. This script calculates the mathematical expression function myFunction() |
Siebel eScript Language Reference |