|
25 | 25 | - [AMD](#amd)
|
26 | 26 | - [A diferença entre call apply bind](#a-diferença-entre-call-apply-bind)
|
27 | 27 | - [simulação para implementar `call` e `apply`](#simulação-para-implementar--call-e--apply)
|
28 | | -- [Implementação de Promise](#promise-implementation) |
| 28 | +- [Implementação de Promise](#implementação-de-promise) |
29 | 29 | - [Implementação do Generator](#generator-implementation)
|
30 | 30 | - [Debouncing](#debouncing)
|
31 | 31 | - [Throttle](#throttle)
|
@@ -804,13 +804,15 @@ Function.prototype.myBind = function (context) {
|
804 | 804 | }
|
805 | 805 | ```
|
806 | 806 |
|
807 | | -# Promise implementation |
| 807 | +# Implementação de Promise |
808 | 808 |
|
809 | | -`Promise` is a new syntax introduced by ES6, which resolves the problem of callback hell. |
| 809 | +`Promise` é a nova sintaxe introduzida pelo ES6, que resolve os problemas de callback hell. |
810 | 810 |
|
811 | | -Promise can be seen as a state machine and it's initial state is `pending`. We can change the state to `resolved` or `rejected` by using the `resolve` and `reject` functions. Once the state is changed, it cannot be changed again. |
| 811 | +Promise pode ser visto como um estado de máquina e o seu estado inicial é `pending`. Nós podemos mudar o estado para `resolved` ou `rejected` usando as funções `resolve` e `reject`. Uma vez que o state mudou, ele não pode mudar novamente. |
812 | 812 |
|
813 | | -The function `then` returns a Promise instance, which is a new instance instead of the previous one. And that's because the Promise specification states that in addition to the `pending` state, other states cannot be changed, and multiple calls of function `then` will be meaningless if the same instance is returned. |
| 813 | +A função `then` retorna uma instância da Promise, do qual é uma nova instância ao invés do anterior. E existe por que a especificação de estado da Promise que adiciona para o estado `pending`, outro estado não pode ser mudado, e multiplas chamadas a função `then` serão insignificantes se a mesma instância for retornada. |
| 814 | + |
| 815 | +Para `then`, ele pode essencialmente ser visto como flatMap`: |
814 | 816 |
|
815 | 817 | For `then`, it can essentially be seen as `flatMap`:
|
816 | 818 |
|
|
0 commit comments