-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype2.js
More file actions
49 lines (40 loc) · 908 Bytes
/
Copy pathprototype2.js
File metadata and controls
49 lines (40 loc) · 908 Bytes
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
/**
* User is an Object Constructor Function
*/
function User(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
this.comment="I am user"
this.name= function(){
return this.firstName+" "+this.lastName;
}
}
//prototype property allows you to add new properties to Object constructors
User.prototype.nationality="Indian"
let user=new User('Ram','Sharma',40,"blue")
console.log(user.nationality);
//Prototype Inheritance
function Admin(){
this.role='Admin'
}
Admin.prototype=User;
const adminNew=new Admin();
console.log(adminNew.comment);
/**
* Example Counter
* As value is
*/
value=5
function makeCounter(){
let value=0;
return this.counter=()=>{
return value++;
}
}
const counter = new makeCounter();
console.log(counter());
console.log(counter());
value=50;
console.log(counter());