Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Class inheritance#182

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
otmon76 merged 1 commit intojavascript-tutorial:masterfromotmon76:1.9.2
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
That's because the child constructor must call `super()`.
Je to proto, že konstruktor dítěte musí volat `super()`.

Here's the corrected code:
Zde je opravený kód:

```js run
classAnimal {
classZvíře {

constructor(name) {
this.name =name;
constructor(jméno) {
this.jméno =jméno;
}

}

classRabbit extendsAnimal {
constructor(name) {
classKrálík extendsZvíře {
constructor(jméno) {
*!*
super(name);
super(jméno);
*/!*
this.created = Date.now();
this.datumVytvoření = Date.now();
}
}

*!*
letrabbit = newRabbit("White Rabbit"); //ok now
letkrálík = newKrálík("Bílý králík"); //nyní v pořádku
*/!*
alert(rabbit.name); //White Rabbit
alert(králík.jméno); //Bílý králík
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,29 +2,29 @@ importance: 5

---

#Error creating an instance
#Chyba při vytváření instance

Here's the code with `Rabbit` extending `Animal`.
Zde je kód, v němž třída `Králík` rozšiřuje třídu `Zvíře`.

Unfortunately, `Rabbit` objects can't be created. What's wrong? Fix it.
Naneštěstí objekty `Králík` nemohou být vytvořeny. Co je špatně? Opravte to.
```js run
classAnimal {
classZvíře {

constructor(name) {
this.name =name;
constructor(jméno) {
this.jméno =jméno;
}

}

classRabbit extendsAnimal {
constructor(name) {
this.name =name;
this.created = Date.now();
classKrálík extendsZvíře {
constructor(jméno) {
this.jméno =jméno;
this.datumVytvoření = Date.now();
}
}

*!*
letrabbit = newRabbit("White Rabbit"); //Error: thisis not defined
letkrálík = newKrálík("Bílý králík"); //Chyba: thisnení definováno
*/!*
alert(rabbit.name);
alert(králík.jméno);
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
classClock {
constructor({template }) {
this.template =template;
classHodiny {
constructor({šablona }) {
this.šablona =šablona;
}

render() {
letdate = new Date();
vypiš() {
letdatum = new Date();

lethours =date.getHours();
if (hours < 10)hours = '0' +hours;
lethodiny =datum.getHours();
if (hodiny < 10)hodiny = '0' +hodiny;

letmins =date.getMinutes();
if (mins < 10)mins = '0' +mins;
letminuty =datum.getMinutes();
if (minuty < 10)minuty = '0' +minuty;

letsecs =date.getSeconds();
if (secs < 10)secs = '0' +secs;
letsekundy =datum.getSeconds();
if (sekundy < 10)sekundy = '0' +sekundy;

letoutput = this.template
.replace('h',hours)
.replace('m',mins)
.replace('s',secs);
letvýstup = this.šablona
.replace('h',hodiny)
.replace('m',minuty)
.replace('s',sekundy);

console.log(output);
console.log(výstup);
}

stop() {
clearInterval(this.timer);
clearInterval(this.časovač);
}

start() {
this.render();
this.timer = setInterval(() => this.render(), 1000);
this.vypiš();
this.časovač = setInterval(() => this.vypiš(), 1000);
}
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
classExtendedClock extendsClock {
constructor(options) {
super(options);
let {precision = 1000 } =options;
this.precision =precision;
classRozšířenéHodiny extendsHodiny {
constructor(možnosti) {
super(možnosti);
let {přesnost = 1000 } =možnosti;
this.přesnost =přesnost;
}

start() {
this.render();
this.timer = setInterval(() => this.render(), this.precision);
this.vypiš();
this.časovač = setInterval(() => this.vypiš(), this.přesnost);
}
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,10 +3,10 @@
<script src="extended-clock.js"></script>

<script>
letlowResolutionClock = newExtendedClock({
template: 'h:m:s',
precision: 10000
});
letpřesnějšíHodiny = newRozšířenéHodiny({
šablona: 'h:m:s',
přesnost: 10000
});

lowResolutionClock.start();
přesnějšíHodiny.start();
</script>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
classClock {
constructor({template }) {
this.template =template;
classHodiny {
constructor({šablona }) {
this.šablona =šablona;
}

render() {
letdate = new Date();
vypiš() {
letdatum = new Date();

lethours =date.getHours();
if (hours < 10)hours = '0' +hours;
lethodiny =datum.getHours();
if (hodiny < 10)hodiny = '0' +hodiny;

letmins =date.getMinutes();
if (mins < 10)mins = '0' +mins;
letminuty =datum.getMinutes();
if (minuty < 10)minuty = '0' +minuty;

letsecs =date.getSeconds();
if (secs < 10)secs = '0' +secs;
letsekundy =datum.getSeconds();
if (sekundy < 10)sekundy = '0' +sekundy;

letoutput = this.template
.replace('h',hours)
.replace('m',mins)
.replace('s',secs);
letvýstup = this.šablona
.replace('h',hodiny)
.replace('m',minuty)
.replace('s',sekundy);

console.log(output);
console.log(výstup);
}

stop() {
clearInterval(this.timer);
clearInterval(this.časovač);
}

start() {
this.render();
this.timer = setInterval(() => this.render(), 1000);
this.vypiš();
this.časovač = setInterval(() => this.vypiš(), 1000);
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
<!DOCTYPE HTML>
<script src="clock.js"></script>
<script>
letclock = newClock({
template: 'h:m:s'
lethodiny = newHodiny({
šablona: 'h:m:s'
});
clock.start();
hodiny.start();


/*Your class should work like this: */
/*Vaše třída by měla fungovat takto: */

/*

letlowResolutionClock = newExtendedClock({
template: 'h:m:s',
precision: 10000
letpřesnějšíHodiny = newRozšířenéHodiny({
šablona: 'h:m:s',
přesnost: 10000
});

lowResolutionClock.start();
přesnějšíHodiny.start();
*/
</script>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,14 +2,14 @@ importance: 5

---

#Extended clock
#Rozšířené hodiny

We've got a `Clock` class. As of now, it prints the time every second.
Máme třídu `Hodiny`, která nyní vypíše čas každou sekundu.


[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` (1second) by default.
Vytvořte novou třídu `RozšířenéHodiny`, která je zděděna z třídy `Hodiny` a přidává parametr `přesnost` --počet milisekund mezi „tiky“. Standardně by měla být `1000` (1sekunda).

-Your code should be in the file `extended-clock.js`
-Don't modify the original`clock.js`.Extend it.
-Váš kód by měl být v souboru `extended-clock.js`.
-Neměňte originální soubor`clock.js`.Rozšiřte jej.
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp