Skip to content

Commit 3421d40

Browse files
authored
Merge pull request #192 from behrends/Constructor_operator_new
Constructor, operator "new" Supiii
2 parents 3ed9dd6 + 14ce48f commit 3421d40

File tree

7 files changed

+102
-110
lines changed

7 files changed

+102
-110
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+
Ja, es ist möglich.
22

3-
If a function returns an object then `new` returns it instead of `this`.
3+
Wenn eine Funktion ein Objekt zurückgibt, dann gibt `new` dieses statt `this` zurück.
44

5-
So they can, for instance, return the same externally defined object `obj`:
5+
So können sie zum Beispiel dasselbe extern definierte Objekt `obj` zurückgeben:
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+
# Zwei Funktionenein Objekt
66

7-
Is it possible to create functions `A` and `B` so that `new A() == new B()`?
7+
Ist es möglich, Funktionen `A` und `B` zu erstellen, sodass `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+
Wenn es möglich ist, gib bitte ein Beispiel für deren Code.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function Calculator() {
1818
let calculator = new Calculator();
1919
calculator.read();
2020

21-
alert( "Sum=" + calculator.sum() );
22-
alert( "Mul=" + calculator.mul() );
21+
alert( "Summe=" + calculator.sum() );
22+
alert( "Produkt=" + calculator.mul() );
2323
```
24+
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
importance: 5
1+
# Erstelle einen neuen Taschenrechner
22

3-
---
3+
Erstelle eine Konstruktorfunktion `Calculator`, die Objekte mit 3 Methoden erstellt:
44

5-
# Create new Calculator
5+
- `read()` fordert zwei Werte an und speichert diese als Objekteigenschaften mit den Namen `a` und `b` entsprechend.
6+
- `sum()` gibt die Summe dieser Eigenschaften zurück.
7+
- `mul()` gibt das Produkt der Multiplikation dieser Eigenschaften zurück.
68

7-
Create a constructor function `Calculator` that creates objects with 3 methods:
8-
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.
12-
13-
For instance:
9+
Zum Beispiel:
1410

1511
```js
1612
let calculator = new Calculator();
1713
calculator.read();
1814

19-
alert( "Sum=" + calculator.sum() );
20-
alert( "Mul=" + calculator.mul() );
15+
alert( "Summe=" + calculator.sum() );
16+
alert( "Produkt=" + calculator.mul() );
2117
```
2218

2319
[demo]
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
2-
31
```js run demo
42
function Accumulator(startingValue) {
53
this.value = startingValue;
64

75
this.read = function() {
8-
this.value += +prompt('How much to add?', 0);
6+
this.value += +prompt('Wieviel soll hinzugefügt werden?', 0);
97
};
108

119
}
@@ -15,3 +13,4 @@ accumulator.read();
1513
accumulator.read();
1614
alert(accumulator.value);
1715
```
16+
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
importance: 5
1+
# Neuen Akkumulator erstellen
22

3-
---
3+
Erstelle eine Konstruktorfunktion `Accumulator(startingValue)`.
44

5-
# Create new Accumulator
5+
Das Objekt, das es erstellt, sollte:
66

7-
Create a constructor function `Accumulator(startingValue)`.
7+
- Den "aktuellen Wert" in der Eigenschaft `value` speichern. Der Anfangswert wird auf den Argumentwert des Konstruktors `startingValue` gesetzt.
8+
- Die `read()` Methode sollte `prompt` verwenden, um eine neue Zahl zu lesen und diese zu `value` hinzuzufügen.
89

9-
Object that it creates should:
10+
Anders ausgedrückt, die Eigenschaft `value` ist die Summe aller von Benutzern eingegebenen Werte mit dem Anfangswert `startingValue`.
1011

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`.
13-
14-
In other words, the `value` property is the sum of all user-entered values with the initial value `startingValue`.
15-
16-
Here's the demo of the code:
12+
Hier ist eine Demo des Codes:
1713

1814
```js
19-
let accumulator = new Accumulator(1); // initial value 1
15+
let accumulator = new Accumulator(1); // Anfangswert 1
2016

21-
accumulator.read(); // adds the user-entered value
22-
accumulator.read(); // adds the user-entered value
17+
accumulator.read(); // addiert den vom Benutzer eingegebenen Wert
18+
accumulator.read(); // addiert den vom Benutzer eingegebenen Wert
2319

24-
alert(accumulator.value); // shows the sum of these values
20+
alert(accumulator.value); // zeigt die Summe dieser Werte
2521
```
2622

2723
[demo]

0 commit comments

Comments
 (0)