-
-
Save roryl/d14806856b35baeffc5e to your computer and use it in GitHub Desktop.
A basic empty closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myArray = ["one","two","three"]; | |
newArray = myArray.map(function(value){ | |
return ucase(value); | |
}); | |
dump(newArray); //outputs ONE, TWO, TREE | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myclosure = function(){ | |
} | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
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 | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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"; | |
expect(isClosure(myClosure)).toBeTrue(); | |
} | |
function testAnonymousClosure() test{ | |
include template="/examples/closures/anonymous_closure.cfm"; | |
expect(newArray).toBe(["ONE","TWO","THREE"]); | |
} | |
function testClosureScopes() test{ | |
include template="/examples/closures/closure_scopes_example.cfm"; | |
expect(function(){outerClosure()}).toThrow(); | |
expect(function(){otherClosure()}).toThrow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment