Skip to content

Commit 0b8d506

Browse files
Constructor, operator "new" (#172)
* Finished article translation along with tasks and tests * Update 1-js/04-object-basics/06-constructor-new/2-calculator-constructor/_js.view/test.js * Update 1-js/04-object-basics/06-constructor-new/2-calculator-constructor/task.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md * Update 1-js/04-object-basics/06-constructor-new/article.md Co-authored-by: Taras <[email protected]>
1 parent 1ba5705 commit 0b8d506

File tree

9 files changed

+114
-114
lines changed

9 files changed

+114
-114
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+
Так, це можливо.
22

3-
If a function returns an object then `new` returns it instead of `this`.
3+
Якщо функція повертає об’єкт, тоді `new` повертає його замість `this`.
44

5-
So they can, for instance, return the same externally defined object `obj`:
5+
Так функції `A` та `B` можуть, наприклад, повертати один і той самий об’єкт `obj`, визначений незалежно від цих функцій:
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 functions – one object
5+
# Дві функції - один об’єкт
66

7-
Is it possible to create functions `A` and `B` so that `new A() == new B()`?
7+
Чи можливо створити функції `A` та `B`, щоб `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+
Якщо так -- наведіть приклад коду таких функцій.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ describe("calculator", function() {
1010
calculator = new Calculator();
1111
calculator.read();
1212
});
13-
14-
it("the read method asks for two values using prompt and remembers them in object properties", function() {
13+
14+
it("метод read запитує два значення за допомогою prompt і запам’ятовує їх у властивостях об’єкта", 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("при введенні 2 і 3 сума дорівнює 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("при введені 2 і 3, добуток дорівнює 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+
# Створити Калькулятор за допомогою конструктора
66

7-
Create a constructor function `Calculator` that creates objects with 3 methods:
7+
Створіть функцію-конструктор `Calculator`, який створює об’єкти з трьома методами:
88

9-
- `read()` asks for two values using `prompt` and remembers them in object properties.
10-
- `sum()` returns the sum of these properties.
11-
- `mul()` returns the multiplication product of these properties.
9+
- `read()` запитує два значення за допомогою `prompt` і запам'ятовує їх у властивостях об’єкта.
10+
- `sum()` повертає суму цих властивостей.
11+
- `mul()` повертає результат множення даних властивостей.
1212

13-
For instance:
13+
Наприклад:
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('Скільки додати?', 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("початкове значення - це аргумент конструктора", 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("після прочитання 0 значення дорівнює 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("після прочитання 1 значення дорівнює 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Accumulator(startingValue) {
55
this.value = startingValue;
66

77
this.read = function() {
8-
this.value += +prompt('How much to add?', 0);
8+
this.value += +prompt('Скільки додати?', 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+
# Створити Accumulator
66

7-
Create a constructor function `Accumulator(startingValue)`.
7+
Створіть функцію-конструктор `Accumulator(startingValue)`.
88

9-
Object that it creates should:
9+
Об’єкт, який він створює повинен:
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+
- Зберігати "поточне значення" у властивості `value`. Початкове значення має значення аргументу конструктора `startingValue`.
12+
- Метод `read()` повинен використовувати `prompt` для зчитування нового числа та додавати його до `value`.
1313

14-
In other words, the `value` property is the sum of all user-entered values with the initial value `startingValue`.
14+
Іншими словами, властивість `value` -- це сума всіх введенних користувачем значень разом із початковим значенням `startingValue`.
1515

16-
Here's the demo of the code:
16+
Нижче ви можете подивитись демонстрацію роботи коду:
1717

1818
```js
19-
let accumulator = new Accumulator(1); // initial value 1
19+
let accumulator = new Accumulator(1); // початкове значення 1
2020

21-
accumulator.read(); // adds the user-entered value
22-
accumulator.read(); // adds the user-entered value
21+
accumulator.read(); // додає введене користувачем значення
22+
accumulator.read(); // додає введене користувачем значення
2323

24-
alert(accumulator.value); // shows the sum of these values
24+
alert(accumulator.value); // показує суму цих значень
2525
```
2626

2727
[demo]

0 commit comments

Comments
 (0)