flushing my list of typos when reaching the Objects chapter
This commit is contained in:
parent
27a491f265
commit
4121423fc0
9 changed files with 27 additions and 27 deletions
|
@ -10,6 +10,6 @@ f = f.bind( {name: "John"} ).bind( {name: "Pete"} );
|
|||
f(); // John
|
||||
```
|
||||
|
||||
The exotic [bound function](https://tc39.github.io/ecma262/#sec-bound-function-exotic-objects) object returned by `f.bind(...)` remembers the context (and arguments if provided) only at the creation time.
|
||||
The exotic [bound function](https://tc39.github.io/ecma262/#sec-bound-function-exotic-objects) object returned by `f.bind(...)` remembers the context (and arguments if provided) only at creation time.
|
||||
|
||||
A function cannot be re-bound.
|
||||
|
|
|
@ -2,7 +2,7 @@ importance: 5
|
|||
|
||||
---
|
||||
|
||||
# Ask loosing this
|
||||
# Ask losing this
|
||||
|
||||
The call to `askPassword()` in the code below should check the password and then call `user.loginOk/loginFail` depending on the answer.
|
||||
|
||||
|
|
|
@ -5,15 +5,15 @@ libs:
|
|||
|
||||
# Function binding
|
||||
|
||||
When using `setTimeout` with object methods or passing object methods along, there's a known problem: "loosing `this`".
|
||||
When using `setTimeout` with object methods or passing object methods along, there's a known problem: "losing `this`".
|
||||
|
||||
Suddenly, `this` just stops working right. The situation is typical for novice developers, but happens with experienced ones as well.
|
||||
|
||||
[cut]
|
||||
|
||||
## Loosing "this"
|
||||
## Losing "this"
|
||||
|
||||
We already know that in JavaScript it's easy to loose `this`. Once a method is passed somewhere separately from the object -- `this` is lost.
|
||||
We already know that in JavaScript it's easy to lose `this`. Once a method is passed somewhere separately from the object -- `this` is lost.
|
||||
|
||||
Here's how it may happen with `setTimeout`:
|
||||
|
||||
|
@ -72,7 +72,7 @@ setTimeout(() => user.sayHi(), 1000); // Hello, John!
|
|||
|
||||
Looks fine, but a slight vulnerability appears in our code structure.
|
||||
|
||||
What is before `setTimeout` triggers (there's one second delay!) `user` changes value? Then, suddenly, the it will call the wrong object!
|
||||
What if before `setTimeout` triggers (there's one second delay!) `user` changes value? Then, suddenly, the it will call the wrong object!
|
||||
|
||||
|
||||
```js run
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue