diff --git a/1-js/7-deeper/2-closure/article.md b/1-js/7-deeper/2-closure/article.md index 63550303..8d619359 100644 --- a/1-js/7-deeper/2-closure/article.md +++ b/1-js/7-deeper/2-closure/article.md @@ -11,7 +11,7 @@ But what happens when outer variables have change? Does a function get a new val Also, what happens when a function travels to another place of the code -- will it get access to variables in the new place? -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. +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. [cut] @@ -776,27 +776,24 @@ In-browser `window` is sometimes used for following purposes: ``` ````smart header="Window and \"this\"" -As we know, usually `this` is used inside an object method to access the object. +As we know, usually `this` is used inside an object method to access the object. But there are special cases when `this` equals `window`: -But outside of that, sometimes `this` equals `window`: - -- The value of the global `this` is `window`: +1. The value of the global `this` is `window`: ```js run // outside of functions alert( this === window ); // true ``` -- When a function with `this` is called in not-strict mode: +2. When a function with `this` is called in not-strict mode: ```js run no-strict - // not in strict mode + // not in strict mode (!) function f() { - alert(this); // [object Window] + alert(this); // [object Window] (in strict mode would be undefined) } f(); // called without an object ``` - That's for compatibility. With `use strict` in the last example `this` would be `undefined`. ```` diff --git a/1-js/plan2.txt b/1-js/plan2.txt index c308a758..35b680ea 100644 --- a/1-js/plan2.txt +++ b/1-js/plan2.txt @@ -53,9 +53,10 @@ data-structures <<< descriptors (TODO: LATER, need JSON to output, better after inheritance to explain getOwnProps) <<< getter setter <<< NFE? -<<< function is object ?? +<<< <<< call/apply? + recursion ( running execution context = where + lexical environment = envrec + outer context stack @@ -63,6 +64,13 @@ recursion ( traverse list task task: traverse list back ) + +<< function is object + name property (obj props, methods, assignments - set it) + length property + +<< NFE + closures LE outer returning a function @@ -70,8 +78,9 @@ closures new Function? counter object? -new function +<< new function +scheduling: settimeout, setinterval bind, currying decorators