js0012

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
<!DOCTYPE html>
<html>

<head>
<title>A not so simple closure</title>
<meta charset="utf-8">
<script src="../assert.js"></script>
<link rel="stylesheet" type="text/css" href="../assert.css">
</head>

<body>
<script>
var outerValue = "samurai";
var later;

function outerFunction() {
var innerValue = "ninja";

function innerFunction() {
assert(outerValue === "samurai", "I can see the samurai.");
assert(innerValue === "ninja", "I can see the ninja.");
}

later = innerFunction;
}

outerFunction();
later();
</script>
</body>
</html>