minor fixes
This commit is contained in:
parent
c48c52cb81
commit
e61bfa2631
1 changed files with 3 additions and 3 deletions
|
@ -88,7 +88,7 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco
|
|||
|
||||
Here `let j = i` declares an "iteration-local" variable `j` and copies `i` into it. Primitives are copied "by value", so we actually get an independent copy of `i`, belonging to the current loop iteration.
|
||||
|
||||
The shooters work correctly, because, the value of `i` now lives a little bit closer. Not in `makeArmy()` Lexical Environment, but in the Lexical Environment that corresponds the current loop iteration:
|
||||
The shooters work correctly, because the value of `i` now lives a little bit closer. Not in `makeArmy()` Lexical Environment, but in the Lexical Environment that corresponds the current loop iteration:
|
||||
|
||||

|
||||
|
||||
|
@ -117,11 +117,11 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco
|
|||
army[5](); // 5
|
||||
```
|
||||
|
||||
That's essentially the same, because, `for` on each iteration generates a new lexical environment, with its own variable `i`. So `shooter` generated in every iteration references its own `i`, from that very iteration.
|
||||
That's essentially the same, because `for` on each iteration generates a new lexical environment, with its own variable `i`. So `shooter` generated in every iteration references its own `i`, from that very iteration.
|
||||
|
||||

|
||||
|
||||
Now, as you've put so much effort into reading this, and the final recipe is so simple - just use `for`, you may wonder -\- was it worth that?
|
||||
Now, as you've put so much effort into reading this, and the final recipe is so simple - just use `for`, you may wonder -- was it worth that?
|
||||
|
||||
Well, if you could easily answer the question, you wouldn't read the solution. So, hopefully this task must have helped you to understand things a bit better.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue