-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritanceInJS2.js
43 lines (38 loc) · 1.35 KB
/
InheritanceInJS2.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
function Person (firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.getName = function() {
// console.log(this);
return `${this.firstName} ${this.lastName}`;
};
let person = new Person('John', 'Doe');
console.log("Person getName() : ")
console.log(person.getName());
function Customer (firstName, lastName, phone, membership) {
Person.call(this,firstName, lastName);
this.phone = phone;
this.membership = membership;
}
console.log("Object.create(Person.prototype) : ");
console.log(Object.create(Person.prototype))
// console.log(Customer.prototype);
Customer.prototype = Object.create(Person.prototype);
// console.log('----------------')
// console.log(Customer.prototype);
console.log("Customer after Object.create() : ");
console.log(Customer.prototype);
Customer.prototype.constructor = Customer;
console.log('After Customer.prototype.constructor = Customer; ');
console.log(Customer.prototype);
let customer1 = new Customer('Tom', 'Smith', '12345', 'Standard');
console.log(customer1);
console.log(customer1.getName());
Customer.prototype.getName = function() {
return `${this.firstName} ${this.lastName} from Customer prototype`;
};
console.log(customer1.getName());
console.log("Person : ");
console.log(person);
console.log("Customer : ");
console.log(customer1);