mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 13:38:43 +00:00
Init inheritance samples
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Javascript Training</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Javascript Training</h1>
|
||||||
|
<script src="./index.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// Inheritance
|
||||||
|
|
||||||
|
class Animal {
|
||||||
|
hello() {
|
||||||
|
return "I'm not define animal yet!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Cat extends Animal {
|
||||||
|
hello() {
|
||||||
|
return super.hello() + " Now, I'm a cat.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Dog extends Animal {
|
||||||
|
hello() {
|
||||||
|
return "I'm a dog.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cat = new Cat();
|
||||||
|
console.log(cat.hello());
|
||||||
|
|
||||||
|
const dog = new Dog();
|
||||||
|
console.log(dog.hello());
|
||||||
Reference in New Issue
Block a user