Skip to content

Class inheritance #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2020
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()`.
Itu karena konstruktor turunan harus memanggil `super()`.

Here's the corrected code:
Berikut kode yang benar:

```js run
class Animal {
Expand All @@ -12,7 +12,7 @@ class Animal {
}

class Rabbit extends Animal {
constructor(name) {
constructor(name) {
*!*
super(name);
*/!*
Expand All @@ -21,7 +21,7 @@ class Rabbit extends Animal {
}

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

---

# Error creating an instance
# Kesalahan saat membuat sebuah _instance_

Here's the code with `Rabbit` extending `Animal`.
Berikut kode dengan `Rabbit` _extending_ `Animal`.

Sayangnya, objek `Rabbit` tidak dapat dibuat. Apa yang salah? Perbaiki!.

Unfortunately, `Rabbit` objects can't be created. What's wrong? Fix it.
```js run
class Animal {

Expand All @@ -17,7 +18,7 @@ class Animal {
}

class Rabbit extends Animal {
constructor(name) {
constructor(name) {
this.name = name;
this.created = Date.now();
}
Expand Down
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: */
/* Kelas kamu harus bekerja seperti ini: */

/*

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

---

# Extended clock

We've got a `Clock` class. As of now, it prints the time every second.
# _Extended clock_

Kita punya kelas `Clock`. Sampai sekarang, ini mencetak waktu setiap detik.

[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.
Buat kelas baru `ExtendedClock` yang diturunkan dari` Clock` dan tambahkan parameter `precision` -- jumlah` ms` antara "ticks". Seharusnya `1000` (1 detik) secara _default_.

- Your code should be in the file `extended-clock.js`
- Don't modify the original `clock.js`. Extend it.
- Kode kamu harus ada di file `extended-clock.js`
- Jangan ubah `clock.js`. Perpanjang itu!.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy