-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype-pattern.js
41 lines (28 loc) · 922 Bytes
/
prototype-pattern.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
/* The Prototype Pattern is a creational design pattern that allows you to create objects based on a prototype or template object.
It's used to create new instances by copying the properties and methods from an existing object */
function Developer(name) {
this.name = name;
this.role = "Devloper";
this.getRole = function () {
return this.role
}
}
Developer.prototype.employeeInfo = function () {
return {
name: this.name,
role: this.role
}
}
function Tester(name) {
this.name = name;
this.role = "Tester";
Developer.call(this, name);
}
Tester.prototype = Object.create(Developer.prototype);
Tester.prototype.constructor = Tester;
const developer = new Developer("Dhanush");
const tester = new Tester("Ajith");
console.log(developer.getRole())
console.log(developer.employeeInfo())
console.log(tester.getRole())
console.log(tester.employeeInfo())