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
@@ -1,6 +1,6 @@
That's because the child constructor must call `super()`.
Det er fordi at konstruktøren skal kalde `super()`.

Here's the corrected code:
Her er den tilrettede kode:

```js run
class Animal {
Expand All @@ -21,7 +21,7 @@ class Rabbit extends Animal {
}

*!*
let rabbit = new Rabbit("White Rabbit"); // ok now
let rabbit = new Rabbit("Hvid kanin"); // ok nu
*/!*
alert(rabbit.name); // White Rabbit
alert(rabbit.name); // Hvid kanin
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Error creating an instance
# Fejl ved oprettelse af instans

Here's the code with `Rabbit` extending `Animal`.
Her er koden hvor `Rabbit` udvider `Animal`.

Unfortunately, `Rabbit` objects can't be created. What's wrong? Fix it.
Uheldigvis kan `Rabbit`-objekter ikke oprettes. Hvad er galt? Ret det.
```js run
class Animal {

Expand All @@ -24,7 +24,7 @@ class Rabbit extends Animal {
}

*!*
let rabbit = new Rabbit("White Rabbit"); // Error: this is not defined
let rabbit = new Rabbit("Hvid kanin"); // Fejl: this is not defined
*/!*
alert(rabbit.name);
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<!DOCTYPE HTML>
<!DOCTYPE html>
<script src="clock.js"></script>
<script>
let clock = new Clock({
template: 'h:m:s'
template: 'h:m:s',
});
clock.start();


/* Your class should work like this: */
/* Din klasse skal virke således: */

/*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ importance: 5

---

# Extended clock
# Udvidet ur

We've got a `Clock` class. As of now, it prints the time every second.
Vi har en `Clock` klasse. Som det er nu udskriver den tiden hver sekund.


[js src="source.view/clock.js"]

Create a new class `ExtendedClock` that inherits from `Clock` and adds the parameter `precision` -- the number of `ms` between "ticks". Should be `1000` (1 second) by default.
Opret en ny klasse `ExtendedClock`, som nedarver fra `Clock` og tilføjer parameteren `precision` -- antallet af `ms` mellem "ticks". Bør være `1000` (1 sekund) som standard.

- Your code should be in the file `extended-clock.js`
- Don't modify the original `clock.js`. Extend it.
- Din kode bør være i filen `extended-clock.js`
- Modificer ikke den originale `clock.js`. Udvid den.
107 changes: 106 additions & 1 deletion 1-js/09-classes/02-class-inheritance/animal-rabbit-extends.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading