You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/7-deeper/2-closure/article.md
+6-9Lines changed: 6 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ But what happens when outer variables have change? Does a function get a new val
11
11
12
12
Also, what happens when a function travels to another place of the code -- will it get access to variables in the new place?
13
13
14
-
We realy should understand what's going on before doing complex things with functions. There is no general programming answer for that. Different languages behave differently. Here we'll concentrate on Javascript.
14
+
We realy should understand what's going on before doing complex things with functions. There is no general programming answer for that. Different languages behave differently. Here we'll cover Javascript of course.
15
15
16
16
[cut]
17
17
@@ -776,27 +776,24 @@ In-browser `window` is sometimes used for following purposes:
776
776
```
777
777
778
778
````smart header="Window and \"this\""
779
-
As we know, usually `this` is used inside an object method to access the object.
779
+
As we know, usually `this` is used inside an object method to access the object.But there are special cases when `this` equals `window`:
780
780
781
-
But outside of that, sometimes `this` equals `window`:
782
-
783
-
- The value of the global`this` is `window`:
781
+
1. The value of the global`this` is `window`:
784
782
785
783
```js run
786
784
// outside of functions
787
785
alert( this === window ); // true
788
786
```
789
787
790
-
- When a function with `this` is called in not-strict mode:
788
+
2. When a function with `this` is called in not-strict mode:
791
789
```js run no-strict
792
-
// not in strict mode
790
+
// not in strict mode (!)
793
791
function f() {
794
-
alert(this); // [object Window]
792
+
alert(this); // [object Window] (in strict mode would be undefined)
795
793
}
796
794
797
795
f(); // called without an object
798
796
```
799
-
That's for compatibility. With `use strict` in the last example `this` would be `undefined`.
0 commit comments