Skip to content

Commit

Permalink
Fix the description of why 'name' ends up on the global object.
Browse files Browse the repository at this point in the history
Close #49.

Signed-off-by: DTrejo <david.daniel.trejo@gmail.com>
  • Loading branch information
mrbkap authored and DTrejo committed Feb 22, 2013
1 parent 818052f commit 5ffbfbe
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions posts/2011-07-26-iteration-demoralization.md
Expand Up @@ -26,26 +26,15 @@ What you might not have guessed, is what this will output:
console.log(window.name); console.log(window.name);
</code> </code>


its: it's:


> "2" > "2"


Iteration is assignment, and without the use of the `var` keyword, you're really using the `this` object - which in the context of a raw function declaration is the `window` object. Iteration is assignment, and without the use of the `var` keyword, you're really using the global object - which in this context is the `window` object.


So the original function is equivalent to: So the original function is equivalent to:


<code>
function allNames() {
var names = [ 'dan', 'anthony', 'pavel' ];
for (this.name in names) {
console.log(name);
}
}
</code>

Which is also equivalent to:

<code> <code>
function allNames() { function allNames() {
var names = [ 'dan', 'anthony', 'pavel' ]; var names = [ 'dan', 'anthony', 'pavel' ];
Expand Down

0 comments on commit 5ffbfbe

Please sign in to comment.