-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaScript Study V Relative Paths.js
62 lines (47 loc) · 1.06 KB
/
JavaScript Study V Relative Paths.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// animal.js
class Animal {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log("Hello");
}
info() {
this.greet();
console.log(`My name is ${this.name}`);
console.log(`I'm ${this.age} years old`);
}
}
export default Animal;
// dog.js
import Animal from "./animal";
class Dog extends Animal {
constructor(name, age, breed) {
super(name, age);
this.breed = breed;
}
info() {
this.greet();
console.log(`My name is ${this.name}`);
console.log(`I am a ${this.breed}`);
console.log(`I'm ${this.age} years old`);
const humanAge = this.getHumanAge();
console.log(`I am ${humanAge} years old in human years`);
}
getHumanAge() {
return this.age * 7;
}
}
export default Dog;
// dogDta.js
import Dog from "../class/dog";
const dog1 = new Dog("Leo", 4, "Chihuahua");
const dog2 = new Dog("Ben", 2, "Poodle");
export { dog1, dog2 };
// script.js
import { dog1, dog2 } from "./data/dogData";
console.log("---------");
dog1.info();
console.log("---------");
dog2.info();