Skip to content

Commit 90e5ecb

Browse files
docs: translate **constructor, operator "new"** article
Constructor, operator "new" by: @PedroDousseau, @jonnathan-ls, @nazarepiedady
2 parents dd27063 + 6e66a8a commit 90e5ecb

File tree

9 files changed

+106
-108
lines changed

9 files changed

+106
-108
lines changed

1-js/04-object-basics/06-constructor-new/1-two-functions-one-object/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Yes, it's possible.
1+
Sim, é possível.
22

3-
If a function returns an object then `new` returns it instead of `this`.
3+
Se uma função retorna um objeto, então `new` o retorna ao invés de `this`.
44

5-
So they can, for instance, return the same externally defined object `obj`:
5+
Então elas podem, por exemplo, retornar o mesmo objeto `obj` definido externamente:
66

77
```js run no-beautify
88
let obj = {};

1-js/04-object-basics/06-constructor-new/1-two-functions-one-object/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 2
22

33
---
44

5-
# Two functionsone object
5+
# Duas funçõesum objeto
66

7-
Is it possible to create functions `A` and `B` so that `new A() == new B()`?
7+
É possível criar funções `A` e `B` tais que `new A()==new B()`?
88

99
```js no-beautify
1010
function A() { ... }
@@ -16,4 +16,4 @@ let b = new B();
1616
alert( a == b ); // true
1717
```
1818

19-
If it is, then provide an example of their code.
19+
Se sim, então forneça um exemplo de seus códigos.

1-js/04-object-basics/06-constructor-new/2-calculator-constructor/_js.view/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ describe("calculator", function() {
1111
calculator.read();
1212
});
1313

14-
it("the read method asks for two values using prompt and remembers them in object properties", function() {
14+
it("o método read solicita por 2 valores usando o prompt e os guarda em propriedades do objeto", function() {
1515
assert.equal(calculator.a, 2);
1616
assert.equal(calculator.b, 3);
1717
});
1818

19-
it("when 2 and 3 are entered, the sum is 5", function() {
19+
it("quando 2 e 3 são inseridos, a soma é 5", function() {
2020
assert.equal(calculator.sum(), 5);
2121
});
2222

23-
it("when 2 and 3 are entered, the product is 6", function() {
23+
it("quando 2 e 3 são inseridos, o produto é 6", function() {
2424
assert.equal(calculator.mul(), 6);
2525
});
2626

1-js/04-object-basics/06-constructor-new/2-calculator-constructor/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ importance: 5
22

33
---
44

5-
# Create new Calculator
5+
# Crie new Calculator
66

7-
Create a constructor function `Calculator` that creates objects with 3 methods:
7+
Crie uma função construtora `Calculator` que crie objetos com 3 métodos:
88

9-
- `read()` prompts for two values and saves them as object properties with names `a` and `b` respectively.
10-
- `sum()` returns the sum of these properties.
11-
- `mul()` returns the multiplication product of these properties.
9+
- `read()` solicita 2 valores e os guarda como propriedades do objeto com nomes `a` e `b` respectivamente.
10+
- `sum()` retorna a soma dessas propriedades.
11+
- `mul()` retorna o produto da multiplicação dessas propriedades.
1212

13-
For instance:
13+
Por exemplo:
1414

1515
```js
1616
let calculator = new Calculator();

1-js/04-object-basics/06-constructor-new/3-accumulator/_js.view/solution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function Accumulator(startingValue) {
22
this.value = startingValue;
33

44
this.read = function() {
5-
this.value += +prompt('How much to add?', 0);
5+
this.value += +prompt('Quanto adicionar?', 0);
66
};
77

88
}

1-js/04-object-basics/06-constructor-new/3-accumulator/_js.view/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ describe("Accumulator", function() {
88
prompt.restore();
99
});
1010

11-
it("initial value is the argument of the constructor", function() {
11+
it("o valor inicial é o argumento do construtor", function() {
1212
let accumulator = new Accumulator(1);
1313

1414
assert.equal(accumulator.value, 1);
1515
});
1616

17-
it("after reading 0, the value is 1", function() {
17+
it("após ler 0, o valor é 1", function() {
1818
let accumulator = new Accumulator(1);
1919
prompt.returns("0");
2020
accumulator.read();
2121
assert.equal(accumulator.value, 1);
2222
});
2323

24-
it("after reading 1, the value is 2", function() {
24+
it("após ler 1, o valor é 2", function() {
2525
let accumulator = new Accumulator(1);
2626
prompt.returns("1");
2727
accumulator.read();

1-js/04-object-basics/06-constructor-new/3-accumulator/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
```js run demo
44
function Accumulator(startingValue) {
55
this.value = startingValue;
6-
6+
77
this.read = function() {
8-
this.value += +prompt('How much to add?', 0);
8+
this.value += +prompt('Quanto quer adicionar?', 0);
99
};
1010

1111
}

1-js/04-object-basics/06-constructor-new/3-accumulator/task.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ importance: 5
22

33
---
44

5-
# Create new Accumulator
5+
# Crie new Accumulator
66

7-
Create a constructor function `Accumulator(startingValue)`.
7+
Crie uma função construtora `Accumulator(startingValue)`.
88

9-
Object that it creates should:
9+
O objeto que ela cria deve:
1010

11-
- Store the "current value" in the property `value`. The starting value is set to the argument of the constructor `startingValue`.
12-
- The `read()` method should use `prompt` to read a new number and add it to `value`.
11+
- Armazenar o "valor atual" na propriedade `value`. O valor inicial é definido no argumento do construtor `startingValue` .
12+
- O método `read()` deve usar `prompt` para ler um novo número e adicioná-lo ao `value`.
1313

14-
In other words, the `value` property is the sum of all user-entered values with the initial value `startingValue`.
14+
Em outras palavras, a propriedade `value` é a soma de todos os valores digitados pelo usuário com o valor inicial `startingValue`.
1515

16-
Here's the demo of the code:
16+
Aqui está uma demonstração do código:
1717

1818
```js
19-
let accumulator = new Accumulator(1); // initial value 1
19+
let accumulator = new Accumulator(1); // valor inicial 1
2020

21-
accumulator.read(); // adds the user-entered value
22-
accumulator.read(); // adds the user-entered value
21+
accumulator.read(); // adiciona o valor digitado pelo usuário
22+
accumulator.read(); // adiciona o valor digitado pelo usuário
2323

24-
alert(accumulator.value); // shows the sum of these values
24+
alert(accumulator.value); // apresenta a soma destes valores
2525
```
2626

2727
[demo]

0 commit comments

Comments
 (0)