Skip to content

Instantly share code, notes, and snippets.

Last active March 11, 2016 10:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A basic empty closure
myArray = ["one","two","three"];
newArray ={
return ucase(value);
dump(newArray); //outputs ONE, TWO, TREE
myclosure = function(){
outerClosure = function(){
var outer = "foo";
innerClosure = function(){
var inner = "bar";
return outer;
echo(innerClosure()); //Outputs foo, the innerClosure had access to the outer variable
return inner; //Errors for inner being undefined, the outer did not have access to the inner
otherClosure = function(){
echo(outer); //Errors for being undefined
echo(inner); //Errors for being undefined
//outerClosure(); //Call outer closure
//otherClosure(); //Call the other closure showing that none of the interal variables can be accessed
* My xUnit Test
component extends="testbox.system.BaseSpec"{
/*********************************** LIFE CYCLE Methods ***********************************/
// executes before all test cases
function beforeTests(){
// executes after all test cases
function afterTests(){
// executes before every test case
function setup( currentMethod ){
// executes after every test case
function teardown( currentMethod ){
/*********************************** TEST CASES BELOW ***********************************/
// Remember that test cases MUST start or end with the keyword 'test'
function testBasicClosure() test{
include template="/examples/closures/basic_closure.cfm";
function testAnonymousClosure() test{
include template="/examples/closures/anonymous_closure.cfm";
function testClosureScopes() test{
include template="/examples/closures/closure_scopes_example.cfm";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment