Access inner function variables in Javascript
Posted
by Elazar Leibovich
on Stack Overflow
See other posts from Stack Overflow
or by Elazar Leibovich
Published on 2010-05-05T18:31:08Z
Indexed on
2010/05/05
18:38 UTC
Read the original article
Hit count: 235
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?
© Stack Overflow or respective owner