Skip to content
Open
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
12 changes: 12 additions & 0 deletions js-core/homeworks/homework-12/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Homework-12</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script src="src/main.js"></script>
</body>
</html>
62 changes: 62 additions & 0 deletions js-core/homeworks/homework-12/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// TASK 1
// Создать класс Human, у которого будут свойства обычного человека:
// имя, возраст, пол, рост, вес.
// Используя прототипное наследование создать дочерние классы Worker
// (дописать в них поля места работы, зарплата, метод "работать")
// и Student (дописать поля места учебы, стипендией, метод "смотреть сериалы")
//
// Создать несколько экземпляров классов Worker и Student, вывести их в консоль.
// Убедиться что они имеют поля родительского класса Human

function Human(options) {
this.name = options.name;
this.age = options.age;
this.sex = options.sex;
this.heigth = options.heigth;
this.weigth = options.weigth;
}

function Worker(...options) {
let obj = options.reduce(elem => elem);
Human.apply(this, options);
this.company = obj.company;
this.salary = obj.salary;
this.works = () => console.log("good work!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make that method as prototype inheritance

}

function Student(...options) {
let obj = options.reduce(elem => elem);
Human.apply(this, options);
this.university = options.university;
this.grants = options.grants;
this.watchSerials = () => console.log("Greate serials!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}

let worker = new Worker({
name: "nastya",
age: 24,
sex: "female",
heigth: 175,
weigth: 65,
salary: 5000,
company: "company name"
});

let student = new Student({
name: "masha",
age: 20,
sex: "female",
heigth: 170,
weigth: 55,
university: "DonNTU",
grants: 500
});

worker.works();

student.watchSerials();

console.log(worker);
console.log(student);