Invoke()
invokes a function/operation of the given object and if given object is a string, Lucee tries to load as component.
Invoke( object=any, name=string, arguments=any );
Returns: object
Examples
<cfscript>
writeDump(label:"structure with invoke()", var:invoke(variables,'myStruct',{a:'First'}));
private function myStruct(){
return "myStruct:"&serializeJson(arguments);
}
<span class="nf">writeDump</span><span class="p">(</span><span class="nv">label</span><span class="p">:</span><span class="s2">"Adding numbers with invoke()"</span><span class="p">,</span> <span class="k">var</span><span class="p">:</span><span class="nf">invoke</span><span class="p">(</span><span class="nv">variables</span><span class="p">,</span><span class="s1">'calc'</span><span class="p">,{</span><span class="nv">a</span><span class="p">:</span><span class="m">3</span><span class="p">,</span><span class="nv">b</span><span class="p">:</span><span class="m">2</span><span class="p">}));</span>
<span class="nv">private</span> <span class="nv">function</span> <span class="nf">calc</span><span class="p">(</span><span class="nv">numeric</span> <span class="nv">a</span><span class="p">,</span> <span class="nv">numeric</span> <span class="nv">b</span><span class="p">){</span>
<span class="nv">return</span> <span class="nv">a</span><span class="o">+</span><span class="nv">b</span><span class="p">;</span>
<span class="p">}</span>
</cfscript>
See also
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)