This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
formula.apply( )
|
formula.apply ({ thisObj {; formulaParams}} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
thisObj | Object |
![]() |
Object to be returned by the This command in the formula | |||||
formulaParams | Collection |
![]() |
Collection of values to be passed as $1...$n when formula is executed | |||||
Function result | Mixed |
![]() |
Value from formula execution | |||||
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}
Product: 4D
Theme: Formulas
Number:
905254
Created: 4D v17 R3
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)