Skip to content

Commit c09bed6

Browse files
committed
UPDATE
1 parent 5ed83a5 commit c09bed6

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

JS/JS-br.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -814,28 +814,26 @@ A função `then` retorna uma instância da Promise, do qual é uma nova instân
814814
815815
Para `then`, ele pode essencialmente ser visto como flatMap`:
816816

817-
For `then`, it can essentially be seen as `flatMap`:
818-
819817
```js
820-
// three states
818+
// árvore de estados
821819
const PENDING = 'pending';
822820
const RESOLVED = 'resolved';
823821
const REJECTED = 'rejected';
824-
// promise accepts a function argument that will execute immediately.
822+
// promise aceita um argumento na função que será executada imediatamente.
825823
function MyPromise(fn) {
826824
let _this = this;
827825
_this.currentState = PENDING;
828826
_this.value = undefined;
829-
// To save the callback of `then`,only cached when the state of the promise is pending,
830-
// at most one will be cached in every instance
827+
// Save o callback do `then`, apenas em cache quando o estado da promise for pending,
828+
// no máximo será cacheado em cada instância
831829
_this.resolvedCallbacks = [];
832830
_this.rejectedCallbacks = [];
833831
834832
_this.resolve = function(value) {
835-
// execute asynchronously to guarantee the execution order
833+
// execute assícronamente para garantir a ordem de execução
836834
setTimeout(() => {
837835
if (value instanceof MyPromise) {
838-
// if value is a Promise, execute recursively
836+
// se o valor é uma Promise, execute recursivamente
839837
return value.then(_this.resolve, _this.reject)
840838
}
841839
if (_this.currentState === PENDING) {
@@ -847,7 +845,7 @@ function MyPromise(fn) {
847845
}
848846
849847
_this.reject = function(reason) {
850-
// execute asynchronously to guarantee the execution order
848+
// execute assícronamente para garantir a ordem de execução
851849
setTimeout(() => {
852850
if (_this.currentState === PENDING) {
853851
_this.currentState = REJECTED;
@@ -857,7 +855,7 @@ function MyPromise(fn) {
857855
})
858856
}
859857
860-
// to solve the following problem
858+
// para resolver o seguinte problema
861859
// `new Promise(() => throw Error('error))`
862860
try {
863861
fn(_this.resolve, _this.reject);
@@ -868,10 +866,10 @@ function MyPromise(fn) {
868866
869867
MyPromise.prototype.then = function(onResolved, onRejected) {
870868
const self = this;
871-
// specification 2.2.7, `then` must return a new promise
869+
// especificação 2.2.7, `then` deve retornar uma nova promise
872870
let promise2;
873-
// specification 2.2, both `onResolved` and `onRejected` are optional arguments
874-
// it should be ignored if `onResolved` or `onRjected` is not a function,
871+
// especificação 2.2, ambos `onResolved` e `onRejected` são argumentos opcionais
872+
// isso deveria ser ignorado se `onResolved` ou `onRjected` não for uma função,
875873
// which implements the penetrate pass of it's value
876874
// `Promise.resolve(4).then().then((value) => console.log(value))`
877875
onResolved = typeof onResolved === 'function' ? onResolved : v => v;

0 commit comments

Comments
 (0)