In this example below I could call tester1(1,2) and get "z", '1' and '2' returned to the console.
var labelTreeSorterClosureTest1 = function() {
var zVar = "z";
return function(a,b) { console.log(zVar), console.log(a), console.log(b) }
}
var tester1 = labelTreeSorterClosureTest1();
But what if I wanted to use a function I had defined elsewhere, such as follows:
function externallyDefinedFunction(a,b) {
console.log(zVar), console.log(a), console.log(b)
}
var labelTreeSorterClosureTest2 = function() {
var zVar = "z";
return externallyDefinedFunction;
}
var tester2 = labelTreeSorterClosureTest2();
If I call 'tester2(1,2)' I get an error saying that 'z' is undefined. Am I attempting to do something that has no meaning?