Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Function object, NFE#182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
EzequielCaste merged 38 commits intojavascript-tutorial:masterfromvplentinax:function-object
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
38 commits
Select commitHold shift + click to select a range
b7007ec
function-object
vplentinaxMay 12, 2020
1c8e647
Merge branch 'master' into function-object
vplentinaxJun 18, 2020
a7b156b
Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-de…
vplentinaxJun 24, 2020
c595a8f
Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-de…
vplentinaxJun 24, 2020
56cd26b
Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-de…
vplentinaxJun 24, 2020
2392a38
Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-de…
vplentinaxJun 24, 2020
d822e87
Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-de…
vplentinaxJun 24, 2020
f8bcc8a
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
vplentinaxJun 24, 2020
3f55e49
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
a6d92eb
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
8f5e3cc
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
6ce7f18
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
dee00be
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
be30350
Update 1-js/06-advanced-functions/06-function-object/5-sum-many-brack…
vplentinaxJun 24, 2020
ddf8b2f
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
dce9fdc
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
d779bc6
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
553d3cd
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
1fb9dc8
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
7214213
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
c5942e8
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
4ff2eba
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
9f42b1c
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
23b52a3
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
b31e2f5
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
555d5e4
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 24, 2020
8717d4f
Update 1-js/06-advanced-functions/06-function-object/2-counter-inc-de…
vplentinaxJun 24, 2020
52c8d81
Update 1-js/06-advanced-functions/06-function-object/article.md
EzequielCasteJun 25, 2020
bf6b207
Update 1-js/06-advanced-functions/06-function-object/article.md
EzequielCasteJun 25, 2020
1acd409
Update 1-js/06-advanced-functions/06-function-object/article.md
EzequielCasteJun 25, 2020
8dbf81c
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 2020
43ea238
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 2020
45f621c
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 2020
48b677e
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 2020
058400e
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 2020
2d16bef
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 2020
7e9e518
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 2020
02a179e
Update 1-js/06-advanced-functions/06-function-object/article.md
vplentinaxJun 25, 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@

The solution uses `count`in the localvariable, but addition methods are written right into the`counter`.They share the same outer lexical environment and also can access the current`count`.
La solución usa `count`en lavariable local, pero los métodos de suma se escriben directamente en el`counter`.Comparten el mismo entorno léxico externo y también pueden acceder al`count` actual.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,14 +2,14 @@ importance: 5

---

#Set and decrease for counter
#Establecer y disminuir un contador

Modify the code of `makeCounter()`so that the counter can also decrease and set the number:
Modifique el código de `makeCounter()`para que el contador también pueda disminuir y establecer el número:

- `counter()`should return the next number (as before).
- `counter.set(value)`should set the counter to `value`.
- `counter.decrease()`should decrease the counter by 1.
- `counter()`debería devolver el siguiente número (como antes).
- `counter.set(value)`debería establecer el contador a `value`.
- `counter.decrease()`debería disminuir el contador en 1.

See the sandbox code for the complete usage example.
Consulte el código en el entorno de pruebas para ver el ejemplo de uso completo.

P.S. You can use either a closure or the function property to keep the current count. Or write both variants.
P.D. Puedes usar un cierre o la propiedad de función para mantener el recuento actual. O escribe ambas variantes.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@

1.For the whole thing to work *anyhow*, the result of `sum`must be function.
2.That function must keep in memory the current value between calls.
3.According to the task, the function must become the number when used in`==`.Functions are objects, so the conversion happens as described in the chapter<info:object-toprimitive>,and we can provide our own method that returns the number.
1.Para que todo funcione *de cualquier forma*, el resultado de `sum`debe ser una función.
2.Esa función debe mantener en la memoria el valor actual entre llamadas.
3.Según la tarea, la función debe convertirse en el número cuando se usa en`==`.Las funciones son objetos, por lo que la conversión se realiza como se describe en el capítulo<info:object-toprimitive>,y podemos proporcionar nuestro propio método para devolver el número.

Now the code:
Ahora el código:

```js run
function sum(a) {
Expand All@@ -28,28 +28,28 @@ alert( sum(6)(-1)(-2)(-3) ); // 0
alert( sum(0)(1)(2)(3)(4)(5) ); // 15
```

Please note that the`sum`function actually works only once. It returns function `f`.
Tenga en cuenta que la función`sum`en realidad solo funciona una vez. Devuelve la función `f`.

Then, on each subsequent call, `f`adds its parameter to the sum `currentSum`,and returns itself.
Luego, en cada llamada posterior, `f`agrega su parámetro a la suma`currentSum`,y se devuelve.

**There is no recursion in the last line of `f`.**
**No hay recursividad en la última línea de `f`.**

Here is what recursion looks like:
Así es como se ve la recursividad:

```js
function f(b) {
currentSum += b;
return f(); // <--recursive call
return f(); // <--llamada recursiva
}
```

And in our case, we just return the function, without calling it:
Y en nuestro caso, solo devolvemos la función, sin llamarla:

```js
function f(b) {
currentSum += b;
return f; // <--does not call itself, returns itself
return f; // <--no se llama a sí mismo, se devuelve
}
```

This `f`will be used in the next call, again return itself, so many times as needed. Then, when used as a number or a string -- the `toString`returns the `currentSum`.We could also use`Symbol.toPrimitive`or `valueOf`here for the conversion.
Esta `f`se usará en la próxima llamada, nuevamente se devolverá, tantas veces como sea necesario. Luego, cuando se usa como un número o una cadena, el `toString`devuelve el `currentSum`.También podríamos usar`Symbol.toPrimitive`o `valueOf`para la conversión.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 2

---

#Sum with an arbitrary amount of brackets
#Suma con una cantidad arbitraria de paréntesis

Write function`sum`that would work like this:
Escriba la función`sum`que funcionaría así:

```js
sum(1)(2) == 3; // 1 + 2
Expand All@@ -14,4 +14,4 @@ sum(6)(-1)(-2)(-3) == 0
sum(0)(1)(2)(3)(4)(5) == 15
```

P.S. Hint: you may need to setup custom object to primitive conversion for your function.
P.D. Sugerencia: es posible que deba configurar una conversión personalizada "objeto a primitiva" en su función.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp