1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
<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>
|