<html> <head> <script type="text/javascript">
var x = "global"; alert("global is:" + x) function f() { var x = "local"; function g() { alert("local is: "+x); } alert("calling g()"); g(); } alert("calling f()"); f(); // Calling this function displays "local"
</script> </head>
<body>
I am still a little confused about closures, but this is a good example to show how javascript scoping works, I would get the source code and try to follow to see how the functions move from one to the next and which variables (x) are in scope at any given time. It explains a lot by seeing it in action. </br>
</body>
</html>
|