-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathcode.js
More file actions
41 lines (28 loc) · 1.19 KB
/
code.js
File metadata and controls
41 lines (28 loc) · 1.19 KB
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
function Parent(attributes) {
this.gender = attributes.gender;
this.age = attributes.age;
this.name = attributes.name;
this.homeTown = attributes.homeTown
}
function Child(attributes) {
Parent.call(this, attributes); // binding to Parent
this.isChild = attributes.isChild; // a special attribute to Child
}
Parent.prototype.yabbaDabba = function () {
return 'Yabba dabba doo!';
};
Parent.prototype.speak = function () {
return `Hello, my name is ${this.name}`;
};
Child.prototype = Object.create(Parent.prototype);
Child.prototype.checkIfChild = function () {
return `My name is ${this.name}.`;// \nAm I a Child? ${pebbles instanceof Child}.\nAm I a Parent? ${pebbles instanceof Parent}.`;
};
const fred = new Parent({ gender: 'Male', age: 35, name: 'Fred', homeTown: 'Bedrock' });
const wilma = new Parent({ gender: 'Female', age: 37, name: 'Wilma', homeTown: 'Bedrock' });
const pebbles = new Child({ gender: 'Female', age: 3, name: 'Pebbles', homeTown: 'Bedrock', isChild: true });
console.log("***** Child *****");
console.log("5.", pebbles);
console.log("6.", pebbles.speak());
console.log("7.", pebbles.checkIfChild());
console.log("8.", pebbles.yabbaDabba());