-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_obj_prototype.js
More file actions
47 lines (35 loc) · 1.02 KB
/
03_obj_prototype.js
File metadata and controls
47 lines (35 loc) · 1.02 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
42
43
44
45
46
47
// Prototypal Inheritance
const Person = function (firstName, lastName, age, likes = []) {
this.firstName = firstName
this.lastName = lastName
this.age = age
this.likes = likes
}
Person.prototype.getBio = function () {
let bio = `${this.firstName} is ${this.age}.`
this.likes.forEach((like) => {
bio += ` ${this.firstName} likes ${like}.`
})
return bio
}
Person.prototype.setName = function (fullName) {
const names = fullName.split(' ')
this.firstName = names[0]
this.lastName = names[1]
}
const me = new Person('Andrew', 'Mead', 27, ['Teaching', 'Biking'])
me.setName('Alexis Turner')
console.log(me.getBio())
const person2 = new Person('Clancey', 'Turner', 51)
console.log(person2.getBio())
Person.prototype.getBio = function () {
let bio = `${this.firstName} issss ${this.age}.`
return bio
}
console.log(me.getBio())
me.getBio = function () {
let bio = `${this.firstName} issssssss ${this.age}.`
return bio
}
console.log(me.getBio())
console.log(person2.getBio())