4D v19

formula.apply( )

Home

 
4D v19
formula.apply( )

formula.apply( )  


 

The formula.apply( ) method executes the formula object to which it is applied and returns the resulting value. The formula object can be created using the Formula or Formula from string commands.

In the thisObj parameter, you can pass a reference to the object to be used as This within the formula.

You can also pass a collection to be used as $1...$n parameters in the formula using the optional formulaParams parameter.

Note that formula.apply( ) is similar to formula.call( ) except that parameters are passed as a collection. This can be useful for passing calculated results.

 $f:=Formula($1+$2+$3)
 
 $c:=New collection(10;20;30)
 $result:=$f.apply(Null;$c// returns 60

 C_OBJECT($calc;$feta;$robot)
 $robot:=New object("name";"Robot";"price";543;"quantity";2)
 $feta:=New object("name";"Feta";"price";12.5;"quantity";5)
 
 $calc:=Formula(This.total:=This.price*This.quantity)
 
 $calc.apply($feta// $feta={name:Feta,price:12.5,quantity:5,total:62.5}
 $calc.apply($robot// $robot={name:Robot,price:543,quantity:2,total:1086}



See also 

formula.call( )

 
PROPERTIES 

Product: 4D
Theme: Formulas

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)