Access inner function variables in Javascript
- by Elazar Leibovich
In many frameworks, internal function variables are used as private variables, for example
Raphael = (function(){
var private = function(a,b) {return a+b;};
var public = function(a) {return private(a,a);}
var object = {mult2:public};
return object;
})();
here, we cannot access from the global namespace the variable named private, as it is an inner variable of the anonymous function in the first line.
Sometimes this function is contains a big Javascript framework, so that it wouldn't pollute the global namespace.
I need to unit tests some object Raphael uses internally (in the above example, I wish to run unit tests on the object private). How can I test them?