Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Is it possible to create functions `A` and `B` so that `new A() == new B()`?
function A() { ... }
function B() { ... }

let a = new A;
let b = new B;
let a = new A();
let b = new B();

alert( a == b ); // true
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@

describe("calculator", function() {
let calculator;
before(function() {
sinon.stub(window, "prompt")

prompt.onCall(0).returns("2");
prompt.onCall(1).returns("3");

calculator = new Calculator();
calculator.read();
});

it("the read method asks for two values using prompt and remembers them in object properties", function() {
assert.equal(calculator.a, 2);
assert.equal(calculator.b, 3);
});

it("when 2 and 3 are entered, the sum is 5", function() {
assert.equal(calculator.sum(), 5);
});

it("when 2 and 3 are entered, the product is 6", function() {
assert.equal(calculator.mul(), 6);
});
let calculator;
before(function() {
sinon.stub(window, "prompt")

prompt.onCall(0).returns("2");
prompt.onCall(1).returns("3");

calculator = new Calculator();
calculator.read();
});

after(function() {
prompt.restore();
});
it("the read method asks for two values using prompt and remembers them in object properties", function() {
assert.equal(calculator.a, 2);
assert.equal(calculator.b, 3);
});

it("when 2 and 3 are entered, the sum is 5", function() {
assert.equal(calculator.sum(), 5);
});

it("when 2 and 3 are entered, the product is 6", function() {
assert.equal(calculator.mul(), 6);
});

after(function() {
prompt.restore();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ importance: 5

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Here's the demo of the code:

```js
let accumulator = new Accumulator(1); // initial value 1

accumulator.read(); // adds the user-entered value
accumulator.read(); // adds the user-entered value

alert(accumulator.value); // shows the sum of these values
```

Expand Down
2 changes: 1 addition & 1 deletion 1-js/04-object-basics/06-constructor-new/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ alert( new SmallUser().name ); // John
Usually constructors don't have a `return` statement. Here we mention the special behavior with returning objects mainly for the sake of completeness.

````smart header="Omitting parentheses"
By the way, we can omit parentheses after `new`, if it has no arguments:
By the way, we can omit parentheses after `new`:

```js
let user = new User; // <-- no parentheses
Expand Down