Depends.
From program logic point of view, variables inside closures are inaccessible from outside, unless explicitly exported.
From a security point of view, one can't access variable values, but may still access a function's definition through toString
. If a function, is not linked to a global variable (including dom), and it's coming from an external file, and is not embedded in the document (in which case one might use innerHTML
), and it's not on the same domain as the page (in which case it would be possible to load the file in an iframe
, and read it's source)... then as far as I know there is no way to access it's source.
It's also possible to override many built-in javascript functions. So the following scenario still exists (unless your code runs before any untrusted code, and never runs again):
<script>
function grab(arg) {
// do something evil.
}
console.log = grab;
</script>
<script>
(function(myArg) {
console.log(myArg);
}('secret'));
</script>