Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
f0c55ba
FIX: change ; to ,
leviding Oct 15, 2020
fe3ba11
OPT: change "false" to "falsy"
leviding Oct 15, 2020
d6f98e1
Fix a possible typo in 1.6.1
vsemozhetbyt Oct 15, 2020
187e8e1
Fix a typo in 1.6.1 task solution
vsemozhetbyt Oct 15, 2020
de8cf9f
FIX: delete extra space
leviding Oct 17, 2020
2f822c8
Fix semicolons in 1.11.1 (Introduction: callbacks)
vsemozhetbyt Oct 30, 2020
c3979cd
Fix typo.
odsantos Oct 31, 2020
0b6cfc9
Update article.md
johnjacobkenny Oct 31, 2020
1236996
Fix a typo in 1.11.3 (Promises chaining)
vsemozhetbyt Oct 31, 2020
d5a88b6
Fix semicolons in 1.11.6 (Promisification)
vsemozhetbyt Oct 31, 2020
9a6a9fb
Update article.md
iliakan Oct 31, 2020
37c6a31
Fix semicolons, remove old note in 1.11.8
vsemozhetbyt Oct 31, 2020
58d9f75
Fix typo in 1.11.6 (Promisification)
vsemozhetbyt Nov 1, 2020
0e0f4e3
Update article.md
iliakan Nov 1, 2020
010bde1
Update article.md
iliakan Nov 1, 2020
dccca58
Update article.md
iliakan Nov 1, 2020
0bdf17e
Fix Optional chaining doc
satyambnsal Nov 1, 2020
05dfb56
Fix typo, add note in 1.12.2 (Async iteration)
vsemozhetbyt Nov 1, 2020
ec81513
Change `var` to `let` in 7.16 regexp-sticky
wam Nov 1, 2020
4e9a335
Correct comment in 1.13.1
vsemozhetbyt Nov 1, 2020
b83f2d7
Fix typos in 'Proxy and Reflect'
vsemozhetbyt Nov 4, 2020
422ef44
Fix outdated note in 1.99.04 (Reference Type)
vsemozhetbyt Nov 5, 2020
e25caae
Correct solution explanation in 1.99.04 (Reference Type)
vsemozhetbyt Nov 5, 2020
bf3c878
Fix link in 2.1.5 (Node properties...)
vsemozhetbyt Nov 5, 2020
b589f38
Merge pull request #2210 from leviding/patch-27
iliakan Nov 9, 2020
9e99c36
Merge pull request #2249 from vsemozhetbyt/patch-9
iliakan Nov 9, 2020
bd23930
Update article.md
leviding Nov 9, 2020
8f91294
Fix typos in 2.1.4 (Searching elements)
vsemozhetbyt Nov 9, 2020
a914bad
fix typo in 06-promisify article.md
ZhaoMuwei Nov 10, 2020
27f6935
Merge pull request #2250 from odsantos/fix-regexp-char-class-typo
iliakan Nov 10, 2020
fd6861e
Merge pull request #2251 from johnjacobkenny/patch-1
iliakan Nov 10, 2020
12a5cb0
Merge pull request #2252 from vsemozhetbyt/patch-10
iliakan Nov 10, 2020
ca9a022
Revert "Fix a typo in 1.11.3 (Promises chaining)"
iliakan Nov 10, 2020
032e18b
Merge pull request #2278 from javascript-tutorial/revert-2252-patch-10
iliakan Nov 10, 2020
2ff5eeb
Merge pull request #2255 from vsemozhetbyt/patch-11
iliakan Nov 10, 2020
48b111d
Merge pull request #2257 from vsemozhetbyt/1.11.8
iliakan Nov 10, 2020
96b9854
Merge pull request #2258 from vsemozhetbyt/patch-12
iliakan Nov 10, 2020
f782e9c
Merge pull request #2259 from satyambnsal/master
iliakan Nov 10, 2020
eba2280
Merge pull request #2260 from vsemozhetbyt/patch-13
iliakan Nov 10, 2020
21d44a0
Merge pull request #2261 from wam/change-var-to-let-in-regexp-sticky-…
iliakan Nov 10, 2020
e9a528f
Merge pull request #2262 from vsemozhetbyt/patch-14
iliakan Nov 10, 2020
bbe7e05
Merge pull request #2266 from vsemozhetbyt/1.99.1
iliakan Nov 10, 2020
876fded
Merge pull request #2270 from vsemozhetbyt/patch-15
iliakan Nov 10, 2020
2f4c29c
Merge pull request #2271 from vsemozhetbyt/patch-16
iliakan Nov 10, 2020
26b393a
Merge pull request #2272 from vsemozhetbyt/patch-17
iliakan Nov 10, 2020
a4194ce
look like ninja code
lumosmind Nov 10, 2020
211db88
Fix typo in 2.1.6 (Attributes and properties)
vsemozhetbyt Nov 10, 2020
59a2f34
Fix a typo in 1.11.3 (Promises chaining)
vsemozhetbyt Nov 10, 2020
7cb6387
Merge pull request #2281 from vsemozhetbyt/patch-10
iliakan Nov 11, 2020
29a7b66
Update article.md
iliakan Nov 11, 2020
fab613d
Merge pull request #2280 from vsemozhetbyt/patch-11
iliakan Nov 11, 2020
fd08e1c
Merge pull request #2279 from lumosmind/patch-53
iliakan Nov 11, 2020
22cf4b6
Merge pull request #2277 from ZhaoMuwei/patch-1
iliakan Nov 11, 2020
5607c77
Merge pull request #2276 from vsemozhetbyt/patch-18
iliakan Nov 11, 2020
5d7cba3
Merge pull request #2275 from leviding/patch-30
iliakan Nov 11, 2020
32d4f13
Merge pull request #2205 from vsemozhetbyt/patch-8
iliakan Nov 11, 2020
ad4bd59
Merge pull request #2204 from vsemozhetbyt/patch-7
iliakan Nov 11, 2020
611236f
Merge pull request #2203 from leviding/patch-25
iliakan Nov 11, 2020
331fafd
Merge pull request #2202 from leviding/patch-24
iliakan Nov 11, 2020
2f7eea9
susy201113
joaquinelio Nov 13, 2020
bb91b69
Update article.md
joaquinelio Nov 13, 2020
6fab64d
Update article.md
joaquinelio Nov 13, 2020
02074f7
Update article.md
joaquinelio Nov 14, 2020
b5fd948
Update article.md
joaquinelio Nov 14, 2020
d522e43
Update article.md
joaquinelio Nov 14, 2020
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/06-advanced-functions/01-recursion/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Podemos esbozarlo como:
</li>
</ul>

Ahí es cuando la función comienza a ejecutarse. La condición `n == 1` es falsa, por lo que el flujo continúa en la segunda rama de` if`:
Ahí es cuando la función comienza a ejecutarse. La condición `n == 1` es falsa, por lo que el flujo continúa en la segunda rama de `if`:

```js run
function pow(x, n) {
Expand Down
2 changes: 1 addition & 1 deletion 1-js/08-prototypes/01-prototype-inheritance/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let rabbit = {
};

*!*
rabbit.__proto__ = animal;
rabbit.__proto__ = animal; // establece rabbit.[[Prototype]] = animal
*/!*
```

Expand Down
8 changes: 4 additions & 4 deletions 1-js/11-async/01-callbacks/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ loadScript('/my/script.js', function(script) {
});
*/!*

})
});

});
```
Expand Down Expand Up @@ -221,7 +221,7 @@ loadScript('1.js', function(error, script) {
});

}
})
});
}
});
```
Expand Down Expand Up @@ -279,7 +279,7 @@ loadScript('1.js', function(error, script) {
}
});
}
})
});
}
});
-->
Expand Down Expand Up @@ -319,7 +319,7 @@ function step3(error, script) {
} else {
// ...continua despues que se han cargado todos los scripts (*)
}
};
}
```

¿Lo Ves? Hace lo mismo, y ahora no hay anidamiento profundo porque convertimos cada acción en una función de nivel superior separada.
Expand Down
17 changes: 8 additions & 9 deletions 1-js/11-async/05-promise-api/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ Entonces para cada promesa obtendremos su estado y `value/error`.
Si el browser no soporta `Promise.allSettled`, es fácil implementarlo:

```js
if(!Promise.allSettled) {
Promise.allSettled = function(promises) {
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
status: 'fulfilled',
value
}), reason => ({
status: 'rejected',
reason
}))));
if (!Promise.allSettled) {
const rejectHandler = reason => ({ status: 'rejected', reason });

const resolveHandler = value => ({ status: 'fulfilled', value });

Promise.allSettled = function (promises) {
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
return Promise.all(convertedPromises);
};
}
```
Expand Down
13 changes: 7 additions & 6 deletions 1-js/11-async/06-promisify/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ function loadScript(src, callback) {

Vamos a promisificarla. La función nueva `loadScriptPromise(src)` va a hacer lo mismo, pero solo acepta `src` (sin callback) y retorna una promesa.

Aquí:
```js
let loadScriptPromise = function(src) {
return new Promise((resolve, reject) => {
loadScript(src, (err, script) => {
if (err) reject(err)
if (err) reject(err);
else resolve(script);
});
})
}
});
};

// uso:
// loadScriptPromise('path/script.js').then(...)
Expand Down Expand Up @@ -66,7 +67,7 @@ function promisify(f) {
f.call(this, ...args); // llama a la función original
});
};
};
}

// uso:
let loadScriptPromise = promisify(loadScript);
Expand Down Expand Up @@ -98,11 +99,11 @@ function promisify(f, manyArgs = false) {
f.call(this, ...args);
});
};
};
}

// Uso:
f = promisify(f, true);
f(...).then(arrayOfResults => ..., err => ...)
f(...).then(arrayOfResults => ..., err => ...);
```
En algunos casos, puede que `err` esté ausente: `callback(result)`, o que haya algo que no es habitual en el formato del callback, por lo que tendremos que promisificar tales funciones manualmente.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/11-async/08-async-await/01-rewrite-async/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function loadJson(url) {
} else {
throw new Error(response.status);
}
})
});
}

loadJson('no-such-user.json')
Expand Down
4 changes: 2 additions & 2 deletions 1-js/11-async/08-async-await/02-rewrite-async-2/task.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Reescribir "rethrow" con async/await

Debajo puedes encontrar el ejemplo "rethrow" del capítulo <info:promise-chaining>. Rescríbelo usando `async/await` en vez de `.then/catch`.
Debajo puedes encontrar el ejemplo "rethrow". Rescríbelo usando `async/await` en vez de `.then/catch`.

Y deshazte de la recursión en favor de un bucle en `demoGithubUser`: con `async/await`, que se vuelve fácil de hacer.

Expand All @@ -22,7 +22,7 @@ function loadJson(url) {
} else {
throw new HttpError(response);
}
})
});
}

// Pide nombres hasta que github devuelve un usuario válido
Expand Down
2 changes: 1 addition & 1 deletion 1-js/11-async/08-async-await/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Thenable {
// resuelve con this.num*2 después de 1000ms
setTimeout(() => resolve(this.num * 2), 1000); // (*)
}
};
}

async function f() {
// espera durante 1 segundo, entonces el resultado se vuelve 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ Explayando más sobre cómo funciona:
- La URL inicial es `https://api.github.com/repos/<repo>/commits`, y la siguiente página estará en la cabecera de `Link` de la respuesta.
- El método `fetch` nos permite suministrar autorización y otras cabeceras si lo necesitamos, aquí GitHub requiere `User-Agent`.
2. Los commits son devueltos en formato JSON.
3. Deberíamos obtener la siguiente URL de la página del `enlace` en el encabezado de la respuesta. Esto tiene un formato especial, por lo que usamos una expresión regular para eso.
3. Deberíamos obtener la siguiente URL de la página del `enlace` en el encabezado de la respuesta. Esto tiene un formato especial, por lo que usamos una expresión regular para eso (aprenderemos esta característica en [Regular expressions](info:regular-expressions)).
- La URL de la página siguiente puede verse así `https://api.github.com/repositories/93253246/commits?page=2`. Eso es generado por el propio Github.
4. Luego entregamos todas las confirmaciones recibidas, y cuando finalizan, se activará la siguiente iteración `while(url)` haciendo una solicitud más.
4. Luego entregamos uno por uno todos los "commit" recibidos y, cuando finalizan, se activará la siguiente iteración `while(url)` haciendo una solicitud más.

Un ejemplo de uso (muestra autores de commit en la consola):

Expand Down
2 changes: 1 addition & 1 deletion 1-js/13-modules/01-modules-intro/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Abajo compare con un script normal:

<script>
*!*
alert(typeof button); // Error: button es indefinido, el script no puede ver los elementos de abjo
alert(typeof button); // button es indefinido, el script no puede ver los elementos de abajo
*/!*
// los scripts normales corren inmediatamente, antes que el resto de la página sea procesada
</script>
Expand Down
2 changes: 1 addition & 1 deletion 1-js/99-js-misc/01-proxy/01-error-nonexisting/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ function wrap(target) {
user = wrap(user);

alert(user.name); // John
alert(user.age); // ReferenceError: Property doesn't exist "age"
alert(user.age); // ReferenceError: Property doesn't exist: "age"
```
2 changes: 1 addition & 1 deletion 1-js/99-js-misc/01-proxy/01-error-nonexisting/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ user = wrap(user);

alert(user.name); // John
*!*
alert(user.age); // ReferenceError: Property doesn't exist "age"
alert(user.age); // ReferenceError: Property doesn't exist: "age"
*/!*
```
8 changes: 4 additions & 4 deletions 1-js/99-js-misc/01-proxy/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ As there are no traps, all operations on `proxy` are forwarded to `target`.

As we can see, without any traps, `proxy` is a transparent wrapper around `target`.

![](proxy.svg)
![](proxy.svg)

`Proxy` is a special "exotic object". It doesn't have own properties. With an empty `handler` it transparently forwards operations to `target`.

Expand Down Expand Up @@ -335,7 +335,7 @@ let user = {
_password: "secret"
};

alert(user._password); // secret
alert(user._password); // secret
```

Let's use proxies to prevent any access to properties starting with `_`.
Expand Down Expand Up @@ -376,7 +376,7 @@ user = new Proxy(user, {
},
*!*
deleteProperty(target, prop) { // to intercept property deletion
*/!*
*/!*
if (prop.startsWith('_')) {
throw new Error("Access denied");
} else {
Expand Down Expand Up @@ -437,7 +437,7 @@ user = {
```


A call to `user.checkPassword()` call gets proxied `user` as `this` (the object before dot becomes `this`), so when it tries to access `this._password`, the `get` trap activates (it triggers on any property read) and throws an error.
A call to `user.checkPassword()` gets proxied `user` as `this` (the object before dot becomes `this`), so when it tries to access `this._password`, the `get` trap activates (it triggers on any property read) and throws an error.

So we bind the context of object methods to the original object, `target`, in the line `(*)`. Then their future calls will use `target` as `this`, without any traps.

Expand Down
4 changes: 2 additions & 2 deletions 1-js/99-js-misc/04-reference-type/3-why-this/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Aquí está la explicación.

2. Lo mismo, aquí los paréntesis no cambian el orden de las operaciones, el punto es el primero de todos modos.

3. Aquí tenemos una llamada más compleja `(expression).method()`. La llamada funciona como si se dividiera en dos líneas:
3. Aquí tenemos una llamada más compleja `(expression)()`. La llamada funciona como si se dividiera en dos líneas:

```js no-beautify
f = obj.go; // Calcula la expresión
Expand All @@ -14,7 +14,7 @@ Aquí está la explicación.

Aquí `f()` se ejecuta como una función, sin `this`.

4. Lo mismo que `(3)`, a la izquierda del punto `.` tenemos una expresión.
4. Lo mismo que `(3)`, a la izquierda de los paréntesis `()` tenemos una expresión.

Para explicar el funcionamiento de `(3)` y `(4)` necesitamos recordar que los accesores de propiedad (punto o corchetes) devuelven un valor del Tipo de Referencia.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/99-js-misc/04-reference-type/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Tipo de Referencia es un tipo interno de "intermediario", con el propósito de p

Cualquier otra operación como la asignación `hi = user.hi` descarta el tipo de referencia como un todo, toma el valor de `user.hi` (una función) y lo pasa. Entonces cualquier operación "pierde" `this`.

Entonces, como resultado, el valor de `this` solo se pasa de la manera correcta si la función se llama directamente usando una sintaxis de punto `obj.method()` o corchetes `obj['method']()` (aquí hacen lo mismo). Más adelante en este tutorial, aprenderemos varias formas de resolver este problema así como [func.bind()](/bind#solution-2-bind).
Entonces, como resultado, el valor de `this` solo se pasa de la manera correcta si la función se llama directamente usando una sintaxis de punto `obj.method()` o corchetes `obj['method']()` (aquí hacen lo mismo). Hay varias formas de resolver este problema, como [func.bind()](/bind#solution-2-bind).

## Resumen

Expand Down
2 changes: 1 addition & 1 deletion 2-ui/1-document/05-basic-dom-node-properties/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ En el modo XML, el caso se mantiene "tal cual". Hoy en día, el modo XML rara ve

## innerHTML: los contenidos

La propiedad [innerHTML](https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML) permite obtener el HTML dentro del elemento como un string.
La propiedad [innerHTML](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin) permite obtener el HTML dentro del elemento como un string.

También podemos modificarlo. Así que es una de las formas más poderosas de cambiar la página.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Por ejemplo, aquí para el estado del pedido se usa el atributo `order-state`:
</div>
```

¿Por qué sería preferible usar un atributo a tener clases como `.order-state-new`, `.order-state-pending`, `order-state-canceled`?
¿Por qué sería preferible usar un atributo a tener clases como `.order-state-new`, `.order-state-pending`, `.order-state-canceled`?

Porque un atributo es más conveniente de administrar. El estado se puede cambiar tan fácil como:

Expand Down
4 changes: 2 additions & 2 deletions 2-ui/5-loading/02-script-async-defer/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ El atributo `async` significa que el script es completamente independiente:

- El navegador no se bloquea con scripts `async` (como `defer`).
- Otros scripts no esperan por scripts `async`, y scripts `async` no espera por ellos.
- El evento `DOMContentLoaded` y los scripts asincrónicos no se esperan entre sí:
- El evento `DOMContentLoaded` puede suceder antes que un script asincrónico (si un script asincrónico termina de cargar una vez la página está completa)
- `DOMContentLoaded` y los scripts asincrónicos no se esperan entre sí:
- `DOMContentLoaded` puede suceder antes que un script asincrónico (si un script asincrónico termina de cargar una vez la página está completa)
- ...o después de un script asincrónico (si tal script asincrónico es pequeño o está en cache)

En otras palabras, los scripts `async` cargan en segundo plano y se ejecutan cuando están listos. El DOM y otros scripts no esperan por ellos, y ellos no esperan por nada. Un totalmente independiente script que se ejecuta en cuanto se ha cargado. Tan simple como es posible, ¿cierto?
Expand Down
2 changes: 1 addition & 1 deletion 5-network/04-fetch-abort/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fetch(url, {

El método `fetch` conoce cómo trabajar con `AbortController`. Este escuchará eventos `abort` sobre `signal`.

Ahora, para abortar, llamamo `controller.abort()`:
Ahora, para abortar, llamamos `controller.abort()`:

```js
controller.abort();
Expand Down
5 changes: 4 additions & 1 deletion 9-regular-expressions/16-regexp-sticky/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ E.g. we have a code string `subject:let varName = "value"`, and we need to read

We'll look for variable name using regexp `pattern:\w+`. Actually, JavaScript variable names need a bit more complex regexp for accurate matching, but here it doesn't matter.

A call to `str.match(/\w+/)` will find only the first word in the line. Or all words with the flag `pattern:g`. But we need only one word at position `4`.
- A call to `str.match(/\w+/)` will find only the first word in the line (`let`). That's not it.
- We can add the flag `pattern:g`. But then the call `str.match(/\w+/g)` will look for all words in the text, while we need one word at position `4`. Again, not what we need.

**So, how to search for a regexp exactly at the given position?**

To search from the given position, we can use method `regexp.exec(str)`.

Expand Down