| <p>This page tests issues of scope with nested functions.</p> | |
| <pre id="console"></pre> | |
| <script> | |
| function log(s) | |
| { | |
| document.getElementById("console").appendChild(document.createTextNode(s + "\n")); | |
| } | |
| function shouldBe(evalA, a, b) | |
| { | |
| if (evalA === b) { | |
| log("PASS: " + a + " should be " + b + " and is."); | |
| } else { | |
| log("FAIL: " + a + " should be " + b + " but instead is " + evalA + "."); | |
| } | |
| } | |
| if (window.testRunner) | |
| testRunner.dumpAsText(); | |
| log("Before parsing f:"); | |
| log("-----"); | |
| shouldBe(typeof f, "typeof f", "function"); | |
| shouldBe(typeof f.f1, "typeof f.f1", "undefined"); | |
| function f(x) | |
| { | |
| function f1() { | |
| log("\nIn call to f:"); | |
| log("-----"); | |
| shouldBe(typeof f, "typeof f", "function"); | |
| shouldBe(typeof f1, "typeof f1", "function"); | |
| shouldBe(typeof f.f1, "typeof f.f1", "undefined"); | |
| shouldBe(typeof x, "typeof x", "number"); | |
| shouldBe(typeof y, "typeof y", "undefined"); | |
| } | |
| f1(); | |
| } | |
| f.y = 1; | |
| log("\nAfter parsing f, but before calling f:"); | |
| log("-----"); | |
| shouldBe(typeof f, "typeof f", "function"); | |
| shouldBe(typeof f.f1, "typeof f.f1", "undefined"); | |
| f(1); | |
| </script> |