Skip to content

Commit 4e7eaba

Browse files
authored
Merge pull request #267 from odsantos/update-en-constructor-operator
Update "Constructor, operator new" files
2 parents 2a66902 + 73dc3aa commit 4e7eaba

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Is it possible to create functions `A` and `B` so that `new A() == new B()`?
1010
function A() { ... }
1111
function B() { ... }
1212

13-
let a = new A;
14-
let b = new B;
13+
let a = new A();
14+
let b = new B();
1515

1616
alert( a == b ); // true
1717
```
Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11

22
describe("calculator", function() {
3-
let calculator;
4-
before(function() {
5-
sinon.stub(window, "prompt")
6-
7-
prompt.onCall(0).returns("2");
8-
prompt.onCall(1).returns("3");
9-
10-
calculator = new Calculator();
11-
calculator.read();
12-
});
13-
14-
it("the read method asks for two values using prompt and remembers them in object properties", function() {
15-
assert.equal(calculator.a, 2);
16-
assert.equal(calculator.b, 3);
17-
});
18-
19-
it("when 2 and 3 are entered, the sum is 5", function() {
20-
assert.equal(calculator.sum(), 5);
21-
});
22-
23-
it("when 2 and 3 are entered, the product is 6", function() {
24-
assert.equal(calculator.mul(), 6);
25-
});
3+
let calculator;
4+
before(function() {
5+
sinon.stub(window, "prompt")
6+
7+
prompt.onCall(0).returns("2");
8+
prompt.onCall(1).returns("3");
9+
10+
calculator = new Calculator();
11+
calculator.read();
12+
});
2613

27-
after(function() {
28-
prompt.restore();
29-
});
14+
it("the read method asks for two values using prompt and remembers them in object properties", function() {
15+
assert.equal(calculator.a, 2);
16+
assert.equal(calculator.b, 3);
17+
});
18+
19+
it("when 2 and 3 are entered, the sum is 5", function() {
20+
assert.equal(calculator.sum(), 5);
21+
});
22+
23+
it("when 2 and 3 are entered, the product is 6", function() {
24+
assert.equal(calculator.mul(), 6);
25+
});
26+
27+
after(function() {
28+
prompt.restore();
3029
});
31-
30+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
Create a constructor function `Calculator` that creates objects with 3 methods:
88

9-
- `read()` asks for two values using `prompt` and remembers them in object properties.
9+
- `read()` prompts for two values and saves them as object properties with names `a` and `b` respectively.
1010
- `sum()` returns the sum of these properties.
1111
- `mul()` returns the multiplication product of these properties.
1212

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Here's the demo of the code:
1717

1818
```js
1919
let accumulator = new Accumulator(1); // initial value 1
20+
2021
accumulator.read(); // adds the user-entered value
2122
accumulator.read(); // adds the user-entered value
23+
2224
alert(accumulator.value); // shows the sum of these values
2325
```
2426

1-js/04-object-basics/06-constructor-new/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ alert( new SmallUser().name ); // John
171171
Usually constructors don't have a `return` statement. Here we mention the special behavior with returning objects mainly for the sake of completeness.
172172

173173
````smart header="Omitting parentheses"
174-
By the way, we can omit parentheses after `new`, if it has no arguments:
174+
By the way, we can omit parentheses after `new`:
175175
176176
```js
177177
let user = new User; // <-- no parentheses

0 commit comments

Comments
 (0)