Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/06-type-conversions/article.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Conversione di tipi

Nella maggior parte dei casi, operatori e funzioni convertono automaticamente il valore nel tipo corretto. Questo viene detto "conversione di tipi".
Nella maggior parte dei casi, operatori e funzioni convertono automaticamente il valore nel tipo corretto.

Ad esempio, `alert` converte automaticamente un valore qualsiasi in una stringa, per poterla mostrare. Le operazioni matematica convertono i valori in numeri.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/14-function-basics/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Questi esempi assumono i significati comuni dei prefissi. Il loro significato di
```smart header="Nomi di funzioni ultra-corti"
Funzioni che vengono utilizzate *molto spesso* potrebbero avere nomi molto corti.

Ad esempio il framework [jQuery](http://jquery.com) definisce una funzione con `$`. La libreria [LoDash](http://lodash.com/) ha nel core una funzione denominata `_`.
Ad esempio il framework [jQuery](http://jquery.com) definisce una funzione con `$`. La libreria [Lodash](http://lodash.com/) ha nel core una funzione denominata `_`.

Queste sono eccezioni. Generalmente i nomi delle funzioni sono precisi e descrittivi.
```
Expand Down
32 changes: 16 additions & 16 deletions 1-js/06-advanced-functions/05-global-object/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ alert("Hello");
window.alert("Hello");
```

LO stesso vale per tutte le altre funzioni integrate, ad esempio possiamo invocare `Array` come `window.Array` e creare le nostre personali propriet�.
Lo stesso vale per tutte le altre funzioni integrate, ad esempio possiamo invocare `Array` come `window.Array` e creare le nostre personali proprietà.

## Browser: l'oggetto "window"

Per ragioni storiche, l'oggetto `window` leggermente incasinato.
Per ragioni storiche, l'oggetto `window` è leggermente incasinato.

1. Fornisce la funzionalit� di "finestra del browser", oltre a svolgere il ruolo di oggetto globale.
1. Fornisce la funzionalità di "finestra del browser", oltre a svolgere il ruolo di oggetto globale.

Possiamo utilizzare `window` per accedere a propriet� e metodi, specifici di una finestra del browser:
Possiamo utilizzare `window` per accedere a proprietà e metodi, specifici di una finestra del browser:

```js run
alert(window.innerHeight); // mostra l'altezza della window

window.open('http://google.com'); // apre una nuova browser window
```

2. Le variabili `var` e le dichiarazioni di funzioni diventano automaticamente delle propriet� di `window`.
2. Le variabili `var` e le dichiarazioni di funzioni diventano automaticamente delle proprietà di `window`.

Ad esempio:
```js untrusted run no-strict refresh
var x = 5;

alert(window.x); // 5 (var x diventa una propriet� di window)
alert(window.x); // 5 (var x diventa una proprietà di window)

window.x = 0;

alert(x); // 0, variabile modificata
```

Da notare che tutto ci� non vale per le dichiarazioni `let/const`:
Da notare che tutto ciò non vale per le dichiarazioni `let/const`:

```js untrusted run no-strict refresh
let x = 5;

alert(window.x); // undefined ("let" non crea propriet� sull'oggetto window)
alert(window.x); // undefined ("let" non crea proprietà sull'oggetto window)
```

3. Inoltre, tutti gli script condividono lo stesso scope globale, quindi le variabili dichiarate all'interno di uno `<script>` diventano visibili anche negli altri:
Expand All @@ -65,25 +65,25 @@ Per ragioni storiche, l'oggetto `window`
</script>
```

4. Un ultima cosa, il valore di `this` nello scope globale `window`.
4. Un'ultima cosa, il valore di `this` nello scope globale è `window`.

```js untrusted run no-strict refresh
alert(this); // window
```

Perch� � stato fatto cosi? Nel momento in cui stato creato il linguaggio, l'idea era quella di fondere diversi aspetti in un unico oggetto `window` per "rendere le cose pi� semplici". Ma da quel momento sono cambiate molte cose. Da piccoli script si passati a grandi applicazioni le quali richiedono una propria architettura.
Perché è stato fatto cosi? Nel momento in cui è stato creato il linguaggio, l'idea era quella di fondere diversi aspetti in un unico oggetto `window` per "rendere le cose più semplici". Ma da quel momento sono cambiate molte cose. Da piccoli script si è passati a grandi applicazioni le quali richiedono una propria architettura.

E' una cosa buona che diversi script (eventualmente anche provenienti da altri sviluppatori) si vedano le variabili a vicenda?

Ovviamente no, questa caratteristica potrebbe portare ad errori dovuti a conflitti tra nomi: due variabili (di script diversi) con uno stesso nome potrebbero aver scopi differenti nei diversi script in cui vengono utilizzate.

Ad oggi, questa caratteristica di `window` viene considerata un errore nel design del linguaggio.

Fortunatamente esiste una soluzione per "aggirare" questo problema, ed chiamata "JavaScript module".
Fortunatamente esiste una soluzione per "aggirare" questo problema, ed è chiamata "JavaScript module".

Se impostiamo `type="module"` come attributo su un tag `<script>`, allora questo script verr� considerato un "modulo" separato con il suo suo personale scope globale (lexical environment), e non interferir� con `window`.
Se impostiamo `type="module"` come attributo su un tag `<script>`, allora questo script verrà considerato un "modulo" separato con il suo suo personale scope globale (lexical environment), e non interferirà con `window`.

- In un modulo, `var x` non diventer� una propriet� di `window`:
- In un modulo, `var x` non diventerà una proprietà di `window`:

```html run
<script type="module">
Expand All @@ -106,7 +106,7 @@ Se impostiamo `type="module"` come attributo su un tag `<script>`, allora questo
</script>
```

- E come ultima cosa, il valore di `this` (al livello globale) in un modulo sar� `undefined` (non avrebbe alcun senso se contenesse `window`?):
- E come ultima cosa, il valore di `this` (al livello globale) in un modulo sarà `undefined` (non avrebbe alcun senso se contenesse `window`?):

```html run
<script type="module">
Expand All @@ -116,11 +116,11 @@ Se impostiamo `type="module"` come attributo su un tag `<script>`, allora questo

**L'utilizzo di `<script type="module">` risolve i difetti di design del linguaggio, separando il livello massimo (top-level) da `window`.**

Pi� avanti tratteremo pi� in dettaglio questo argomento, nel capitolo [](info:modules).
Più avanti tratteremo più in dettaglio questo argomento, nel capitolo [](info:modules).

## Utilizzi sensati dell'oggetto globale

1. L'utilizzo delle variabili globali, solitamente sconsigliato. Dovrebbero esserci il minor numero di variabili globali possibili, ma se proprio ne avessimo bisogno possiamo comunque sfruttare l'oggetto globale `window` (o `global` in Node.js).
1. L'utilizzo delle variabili globali, solitamente è sconsigliato. Dovrebbero esserci il minor numero di variabili globali possibili, ma se proprio ne avessimo bisogno possiamo comunque sfruttare l'oggetto globale `window` (o `global` in Node.js).

Qui inseriamo delle informazioni riguardo l'utente nell'oggetto globale, in modo tale da renderle accessibili anche agli altri script:

Expand Down
2 changes: 1 addition & 1 deletion 1-js/08-prototypes/02-function-prototype/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ On the picture, `"prototype"` is a horizontal arrow, meaning a regular property,
```smart header="`F.prototype` only used at `new F` time"
`F.prototype` property is only used when `new F` is called, it assigns `[[Prototype]]` of the new object. After that, there's no connection between `F.prototype` and the new object. Think of it as a "one-time gift".

If, after the creation, `F.prototype` property changes (`F.property = <another object>`), then new objects created by `new F` will have another object as `[[Prototype]]`, but already existing objects keep the old one.
If, after the creation, `F.prototype` property changes (`F.prototype = <another object>`), then new objects created by `new F` will have another object as `[[Prototype]]`, but already existing objects keep the old one.
```

## Default F.prototype, constructor property
Expand Down
2 changes: 1 addition & 1 deletion 1-js/09-classes/01-class/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ alert(typeof User); // function

What `class User {...}` construct really does is:
1. Creates a function named `User`, that becomes the result of the class declaration.
- The function code is taken from the `constructor` method (assumed empty is we don't write such method).
- The function code is taken from the `constructor` method (assumed empty if we don't write such method).
3. Stores all methods, such as `sayHi`, in `User.prototype`.

Afterwards, for new objects, when we call a method, it's taken from the prototype, just as described in the chapter <info:function-prototype>. So `new User` object has access to class methods.
Expand Down
2 changes: 1 addition & 1 deletion 1-js/13-modules/02-import-export/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export {default as Github} from './providers/github.js';
````warn header="Re-exporting default is tricky"
Please note: `export User from './user.js'` won't work. It's actually a syntax error. To re-export the default export, we must mention it explicitly `{default as ...}`, like in the example above.

Also, there's another oddity: `export * from './user.js'` re-exports only named exports, exluding the default one. Once again, we need to mention it explicitly.
Also, there's another oddity: `export * from './user.js'` re-exports only named exports, excluding the default one. Once again, we need to mention it explicitly.

For instance, to re-export everything, two statements will be necessary:
```js
Expand Down
3 changes: 2 additions & 1 deletion 8-web-components/1-webcomponents-intro/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Components may have subcomponents, e.g. messages may be parts of a higher-level

How do we decide, what is a component? That comes from intuition, experience and common sense. Usually it's a separate visual entity that we can describe in terms of what it does and how it interacts with the page. In the case above, the page has blocks, each of them plays its own role, it's logical to make these components.

- A component has its own JavaScript class.
A component has:
- its own JavaScript class.
- DOM structure, managed solely by its class, outside code doesn't access it ("encapsulation" principle).
- CSS styles, applied to the component.
- API: events, class methods etc, to interact with other components.
Expand Down
20 changes: 10 additions & 10 deletions 9-regular-expressions/02-regexp-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ There are two sets of methods to deal with regular expressions.

Which method to use depends on what we'd like to do.

Methods become much easier to understand if we separate them by their use in real-life tasks:
Methods become much easier to understand if we separate them by their use in real-life tasks.

So, here are general recipes, the details to follow:

**To search for all matches:**

Expand All @@ -30,9 +32,7 @@ Use regexp `g` flag and:
**To split the string by a separator:**
- `str.split(str|reg)`

Now you get the details about every method in this chapter... But if you're reading for the first time, and want to know more about regexps - go ahead!

You may want to skip methods for now, move on to the next chapter, and then return here if something about a method is unclear.
Now you can continue reading this chapter to get the details about every method... But if you're reading for the first time, then you probably want to know more about regexps. So you can move to the next chapter, and then return here if something about a method is unclear.

## str.search(reg)

Expand All @@ -41,12 +41,12 @@ We've seen this method already. It returns the position of the first match or `-
```js run
let str = "A drop of ink may make a million think";

alert( str.search( *!*/a/i*/!* ) ); // 0 (the first position)
alert( str.search( *!*/a/i*/!* ) ); // 0 (first match at zero position)
```

**The important limitation: `search` only finds the first match.**

We can't find next positions using `search`, there's just no syntax for that. But there are other methods that can.
We can't find next matches using `search`, there's just no syntax for that. But there are other methods that can.

## str.match(reg), no "g" flag

Expand Down Expand Up @@ -215,9 +215,9 @@ alert('12-34-56'.split(/-/)) // array of [12, 34, 56]

## str.replace(str|reg, str|func)

That's actually a great method, one of most useful ones. The swiss army knife for searching and replacing.
This is a generic method for searching and replacing, one of most useful ones. The swiss army knife for searching and replacing.

The simplest use -- searching and replacing a substring, like this:
We can use it without regexps, to search and replace a substring:

```js run
// replace a dash by a colon
Expand Down Expand Up @@ -263,7 +263,7 @@ Quite often we'd like to reuse parts of the source string, recombine them in the

To do so, we should:
1. First, mark the parts by parentheses in regexp.
2. Use `$1`, `$2` (and so on) in the replacement string to get the content matched by parentheses.
2. Use `$1`, `$2` (and so on) in the replacement string to get the content matched by 1st, 2nd and so on parentheses.

For instance:

Expand Down Expand Up @@ -433,7 +433,7 @@ alert( regexp.test(str) ); // false (no match)


````warn header="Same global regexp tested repeatedly may fail to match"
If we apply the same global regexp to different inputs, it may lead to wrong result, because `regexp.test` call advances `regexp.lastIndex` property, so next matches start from non-zero position.
If we apply the same global regexp to different inputs, it may lead to wrong result, because `regexp.test` call advances `regexp.lastIndex` property, so the search in another string may start from non-zero position.

For instance, here we call `regexp.test` twice on the same text, and the second time fails:

Expand Down