Skip to content

Commit f1080b1

Browse files
authored
Merge pull request #190 from javascript-tutorial/sync-2d5be7b7
Sync with upstream @ 2d5be7b
2 parents d188c83 + cd2ec2f commit f1080b1

File tree

8 files changed

+13
-11
lines changed

8 files changed

+13
-11
lines changed

1-js/06-advanced-functions/04-var/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ In all the above cases we declare a Function Expression and run it immediately.
264264

265265
There are two main differences of `var`:
266266

267-
1. `var` variables have no block scope; their visibility is scoped to current function, or global, if declared outside function.
267+
1. `var` variables have no block scope, their visibility is scoped to current function, or global, if declared outside function.
268268
2. `var` declarations are processed at function start (script start for globals).
269269

270270
There's one more very minor difference related to the global object, that we'll cover in the next chapter.

1-js/06-advanced-functions/05-global-object/article.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Objeto global
33

4-
O objeto global fornece variáveis e funções que estão disponíveis em qualquer lugar. Em sua maioria, aqueles que são incorporados ao idioma ou ao ambiente.
4+
O objeto global fornece variáveis e funções que estão disponíveis em qualquer lugar. Na sua maioria, aquelas que são incorporadas ao idioma ou ao ambiente.
55

66
No navegador ele é chamado de `window`, no Node.js é `global`, em outros ambientes pode ter outro nome.
77

@@ -25,6 +25,8 @@ var gVar = 5;
2525
alert(window.gVar); // 5 (se torna uma propriedade do objeto global)
2626
```
2727

28+
O mesmo efeito têm declarações de função (instruções com a palavra-chave `function` no fluxo principal do código, não expressões de função).
29+
2830
Por favor, não confie nisso! Esse comportamento existe por motivos de compatibilidade. Scripts modernos usam [JavaScript modules](info:modules) onde tal coisa não acontece.
2931

3032
Se usássemos `let`, isso não aconteceria:

1-js/06-advanced-functions/06-function-object/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ If the function is declared as a Function Expression (not in the main code flow)
347347

348348
Also, functions may carry additional properties. Many well-known JavaScript libraries make great use of this feature.
349349

350-
They create a "main" function and attach many other "helper" functions to it. For instance, the [jQuery](https://jquery.com) library creates a function named `$`. The [lodash](https://lodash.com) library creates a function `_`, and then adds `_.clone`, `_.keyBy` and other properties to it (see the [docs](https://lodash.com/docs) when you want learn more about them). Actually, they do it to lessen their pollution of the global space, so that a single library gives only one global variable. That reduces the possibility of naming conflicts.
350+
They create a "main" function and attach many other "helper" functions to it. For instance, the [jQuery](https://jquery.com) library creates a function named `$`. The [lodash](https://lodash.com) library creates a function `_`, and then adds `_.clone`, `_.keyBy` and other properties to it (see the [docs](https://lodash.com/docs) when you want to learn more about them). Actually, they do it to lessen their pollution of the global space, so that a single library gives only one global variable. That reduces the possibility of naming conflicts.
351351

352352

353353
So, a function can do a useful job by itself and also carry a bunch of other functionality in properties.

1-js/06-advanced-functions/07-new-function/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Perhaps we want it to be able to access outer local variables?
9191

9292
The problem is that before JavaScript is published to production, it's compressed using a *minifier* -- a special program that shrinks code by removing extra comments, spaces and -- what's important, renames local variables into shorter ones.
9393

94-
For instance, if a function has `let userName`, minifier replaces it `let a` (or another letter if this one is occupied), and does it everywhere. That's usually a safe thing to do, because the variable is local, nothing outside the function can access it. And inside the function, minifier replaces every mention of it. Minifiers are smart, they analyze the code structure, so they don't break anything. They're not just a dumb find-and-replace.
94+
For instance, if a function has `let userName`, minifier replaces it with `let a` (or another letter if this one is occupied), and does it everywhere. That's usually a safe thing to do, because the variable is local, nothing outside the function can access it. And inside the function, minifier replaces every mention of it. Minifiers are smart, they analyze the code structure, so they don't break anything. They're not just a dumb find-and-replace.
9595

9696
But, if `new Function` could access outer variables, then it would be unable to find `userName`, since this is passed in as a string *after* the code is minified.
9797

1-js/06-advanced-functions/08-settimeout-setinterval/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ setTimeout(() => { clearInterval(timerId); alert('stop'); }, 5000);
130130
```smart header="Modal windows freeze time in Chrome/Opera/Safari"
131131
In browsers IE and Firefox the internal timer continues "ticking" while showing `alert/confirm/prompt`, but in Chrome, Opera and Safari the internal timer becomes "frozen".
132132
133-
So if you run the code above and don't dismiss the `alert` window for some time, then in Firefox/IE next `alert` will be shown immediately as you do it (2 seconds passed from the previous invocation), and in Chrome/Opera/Safari -- after 2 more seconds (timer did not tick during the `alert`).
133+
So if you run the code above and don't dismiss the `alert` window for some time, then the next `alert` will be shown immediately as you do it. The actual interval between alerts will be shorter than 2 seconds.
134134
```
135135

136136
## Nested setTimeout
@@ -382,7 +382,7 @@ First timers run immediately (just as written in the spec), and then the delay c
382382
383383
That limitation comes from ancient times and many scripts rely on it, so it exists for historical reasons.
384384
385-
For server-side JavaScript, that limitation does not exist, and there exist other ways to schedule an immediate asynchronous job, like [process.nextTick](https://nodejs.org/api/process.html) and [setImmediate](https://nodejs.org/api/timers.html) for Node.js. So the notion is browser-specific only.
385+
For server-side JavaScript, that limitation does not exist, and there exist other ways to schedule an immediate asynchronous job, like [setImmediate](https://nodejs.org/api/timers.html#timers_setimmediate_callback_args) for Node.js. So this note is browser-specific.
386386
````
387387

388388
### Allowing the browser to render
@@ -447,7 +447,7 @@ Now the `<div>` shows increasing values of `i`.
447447
- To cancel the execution, we should call `clearTimeout/clearInterval` with the value returned by `setTimeout/setInterval`.
448448
- Nested `setTimeout` calls are a more flexible alternative to `setInterval`, allowing us to set the time *between* executions more precisely.
449449
- Zero delay scheduling with `setTimeout(func, 0)` (the same as `setTimeout(func)`) is used to schedule the call "as soon as possible, but after the current script is complete".
450-
- The browser limits the minimal delay for five or more nested call of `setTimeout` or for `setInterval` (after 5th call) to 4ms. That's for historical reasons.
450+
- The browser limits the minimal delay for five or more nested calls of `setTimeout` or for `setInterval` (after 5th call) to 4ms. That's for historical reasons.
451451

452452
Please note that all scheduling methods do not *guarantee* the exact delay. We should not rely on that in the scheduled code.
453453

1-js/08-prototypes/01-prototype-inheritance/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ alert(admin.fullName); // John Smith (*)
199199
// setter triggers!
200200
admin.fullName = "Alice Cooper"; // (**)
201201

202-
alert(admin.fullName); // Alice Cooper , state of admin modified
203-
alert(user.fullName); // John Smith , state of user protected
202+
alert(admin.fullName); // Alice Cooper, state of admin modified
203+
alert(user.fullName); // John Smith, state of user protected
204204
```
205205

206206
Here in the line `(*)` the property `admin.fullName` has a getter in the prototype `user`, so it is called. And in the line `(**)` the property has a setter in the prototype, so it is called.

2-ui/2-events/02-bubbling-and-capturing/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ The event handling process:
197197
198198
- Then the event moves down from the document root to `event.target`, calling handlers assigned with `addEventListener(..., true)` on the way (`true` is a shorthand for `{capture: true}`).
199199
- Then handlers are called on the target element itself.
200-
- Then the event bubbles up from `event.target` to the root, calling handlers assigned using `on<event>` and `addEventListener` without the 3rd argument or with the 3rd argument `false/{capture:false}`.
200+
- Then the event bubbles up from `event.target` to the root, calling handlers assigned using `on<event>`, HTML attributes and `addEventListener` without the 3rd argument or with the 3rd argument `false/{capture:false}`.
201201
202202
Each handler can access `event` object properties:
203203

2-ui/2-events/03-event-delegation/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Capturing and bubbling allow us to implement one of most powerful event handling
55

66
The idea is that if we have a lot of elements handled in a similar way, then instead of assigning a handler to each of them -- we put a single handler on their common ancestor.
77

8-
In the handler we get `event.target`, see where the event actually happened and handle it.
8+
In the handler we get `event.target` to see where the event actually happened and handle it.
99

1010
Let's see an example -- the [Ba-Gua diagram](http://en.wikipedia.org/wiki/Ba_gua) reflecting the ancient Chinese philosophy.
1111

0 commit comments

Comments
 (0)