work
This commit is contained in:
parent
3f5f2cac8b
commit
438e7aef2e
2 changed files with 17 additions and 11 deletions
|
@ -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?
|
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]
|
[cut]
|
||||||
|
|
||||||
|
@ -776,27 +776,24 @@ In-browser `window` is sometimes used for following purposes:
|
||||||
```
|
```
|
||||||
|
|
||||||
````smart header="Window and \"this\""
|
````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`:
|
1. The value of the global `this` is `window`:
|
||||||
|
|
||||||
- The value of the global `this` is `window`:
|
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
// outside of functions
|
// outside of functions
|
||||||
alert( this === window ); // true
|
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
|
```js run no-strict
|
||||||
// not in strict mode
|
// not in strict mode (!)
|
||||||
function f() {
|
function f() {
|
||||||
alert(this); // [object Window]
|
alert(this); // [object Window] (in strict mode would be undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
f(); // called without an object
|
f(); // called without an object
|
||||||
```
|
```
|
||||||
That's for compatibility. With `use strict` in the last example `this` would be `undefined`.
|
|
||||||
|
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,10 @@ data-structures
|
||||||
<<< descriptors (TODO: LATER, need JSON to output, better after inheritance to explain getOwnProps)
|
<<< descriptors (TODO: LATER, need JSON to output, better after inheritance to explain getOwnProps)
|
||||||
<<< getter setter
|
<<< getter setter
|
||||||
<<< NFE?
|
<<< NFE?
|
||||||
<<< function is object ??
|
<<<
|
||||||
<<< call/apply?
|
<<< call/apply?
|
||||||
|
|
||||||
|
|
||||||
recursion (
|
recursion (
|
||||||
running execution context = where + lexical environment = envrec + outer
|
running execution context = where + lexical environment = envrec + outer
|
||||||
context stack
|
context stack
|
||||||
|
@ -63,6 +64,13 @@ recursion (
|
||||||
traverse list task
|
traverse list task
|
||||||
task: traverse list back
|
task: traverse list back
|
||||||
)
|
)
|
||||||
|
|
||||||
|
<< function is object
|
||||||
|
name property (obj props, methods, assignments - set it)
|
||||||
|
length property
|
||||||
|
|
||||||
|
<< NFE
|
||||||
|
|
||||||
closures
|
closures
|
||||||
LE outer
|
LE outer
|
||||||
returning a function
|
returning a function
|
||||||
|
@ -70,8 +78,9 @@ closures
|
||||||
new Function?
|
new Function?
|
||||||
counter object?
|
counter object?
|
||||||
|
|
||||||
new function
|
<< new function
|
||||||
|
|
||||||
|
scheduling: settimeout, setinterval
|
||||||
|
|
||||||
bind, currying
|
bind, currying
|
||||||
decorators
|
decorators
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue