105
rated 0 times
[
107]
[
2]
/ answers: 1 / hits: 32697
/ 12 Years ago, thu, january 17, 2013, 12:00:00
Say I have this anonymous function:
(function(window){
var private = 'private msg';
function sayit() {
alert(private) // works
}
document.body.onclick = sayit; // works
})(window);
// private shouldn't be accessible here
Is this how JavaScript should behave?
That is, there is no way to access private
from anywhere outside of that anonymous function?
If so, is it possible to find some kind of hack to access private
from the outside, leaving the code the way it is?
More From » scope