Skip to content

Commit

Permalink
scope and closures: renaming swapping fig1 and fig2
Browse files Browse the repository at this point in the history
  • Loading branch information
getify committed Dec 10, 2019
1 parent d8027e9 commit 00592ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scope-closures/ch2.md
Expand Up @@ -45,11 +45,11 @@ console.log(nextStudent);

We've designated 3 scope colors with code comments: RED (outermost global scope), BLUE (scope of function `getStudentName(..)`), and GREEN (scope of/inside the `for` loop). But it still may be difficult to recognize the boundaries of these scope buckets when looking at a code listing.

Figure 2 tries to make the scope boundaries easier to visualize by drawing colored bubbles around each scope:
Figure 1 tries to make the scope boundaries easier to visualize by drawing colored bubbles around each scope:

<figure>
<img src="fig2.png" width="500" alt="Nested Scope Bubbles" align="center">
<figcaption><em>Fig. 2: Nested Scope Bubbles</em></figcaption>
<img src="fig1.png" width="500" alt="Nested Scope Bubbles" align="center">
<figcaption><em>Fig. 1: Nested Scope Bubbles</em></figcaption>
</figure>

1. **Bubble 1** (RED) encompasses the global scope, which has three identifiers/variables: `students` (line 1), `getStudentName` (line 8), and `nextStudent` (line 16).
Expand Down Expand Up @@ -256,7 +256,11 @@ This sort of accident (almost certain to lead to bugs eventually) is a great exa

To visualize nested scope resolution, yet another useful metaphor may be an office building:

<img src="fig1.png" width="250">
<figure>
<img src="fig2.png" width="250" alt="Scope &quot;Building&quot;" align="center">
<figcaption><em>Fig. 2: Scope "Building"</em></figcaption>
<br><br>
</figure>

The building represents our program's nested scope rule set. The first floor of the building represents the currently executing scope. The top level of the building is the global scope.

Expand Down
Binary file modified scope-closures/fig1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scope-closures/fig2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 00592ad

Please sign in to comment.