Skip to content

Instantly share code, notes, and snippets.

@roryl
Last active February 9, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save roryl/468f346631ec9afa3cf9 to your computer and use it in GitHub Desktop.
Save roryl/468f346631ec9afa3cf9 to your computer and use it in GitHub Desktop.
First Class Functions - Examples of passing classes around
component {
public function init(){
return this;
}
public function otherFunc(){
echo("called!");
}
}
component {
public function init(){
var a = new component_a(); //instantiate a
this.otherFunc = a.otherFunc; //Copy otherFunc from a to b
this.otherFunc(); //Outputs "called!"
call(this.otherFunc);
return this;
}
private function call(required function func){
echo(arguments.func()); //An example of passing a function, executes otherFunc, outputs "called!"
}
}
/**
* 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 componentATest(){
new component_a();
}
function componentBTest(){
new component_b();
}
function componentBOutputTest(){
savecontent variable="outputs"{
new component_b();
}
expect(outputs).toBe("called!called!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment