Closures for CFMX

PDF HTML FlashPaper

Main

Closures for CFMX

A closure is a function or code block that can have both bound and unbound variables. A bound variable is tied to the environment in which the closure is created. An unbound variable does not get an associated value until the closure is executed.

For example:

<cfset cf = createObject("component","ClosureFactory") />

<cfset mult = cf.new("a * b") />

<cfset double = mult.bind(a = 2) />

In this example, both a and b are unbound variables in mult but a is bound to 2 in double.

When you execute the mult closure, it will allow both a and b to bind to any accessible variables with those names. When you execute the double closure, it only needs to allow b to bind to an accessible variable.