-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeveloper_Manager_Person_Advanced.js
56 lines (43 loc) · 1.82 KB
/
Developer_Manager_Person_Advanced.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
/* --------------------------- Person constructor --------------------------- */
function Person(name, age){
// your code here ...
this.name = name;
this.age = age;
}
// Person greet method
// your code here ...
Person.prototype.greet = function(){
if (this instanceof Developer){
console.log(`Hi, I'm ${this.name} and I'm ${this.age} years old. I know ${this.skillset}`);
} else if(this instanceof Manager){
console.log(`Hi, I'm ${this.name} and I'm ${this.age} years old. I manage ${this.managed.map(el => el.name)}`);
}
}
/* --------------------------- Manager constructor -------------------------- */
function Manager(name, age, managed){
// reuse Person constructor
// your code here ...
Person.call(this, name,age);
this.managed = managed;
}
// Manager objects should inherit all methods from Person:
/* -------------------------- Developer constructor ------------------------- */
function Developer(name, age, skillset){
// reuse Person constructor
// your code here ...
Person.call(this, name,age);
this.skillset = skillset;
}
// Developer objects should inherit all methods from Person:
Manager.prototype = Object.create(Person.prototype);
Developer.prototype = Object.create(Person.prototype);
/* ----------------------------- Create Objects ----------------------------- */
// Developer instances
let maria = new Developer('Maria Popova', 23, ['Python', 'Machine Learning']);
let pesho = new Developer('Petar Petrov', 19, ['JavaScript', 'Angular', 'React', 'Vue']);
// Manager instances
let gates = new Manager('Bill Gates', 43, [maria, pesho]);
/* ----------------------------- Use the objects ---------------------------- */
maria.greet();
pesho.greet();
gates.greet();