-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path36_index36.js
73 lines (61 loc) · 2.06 KB
/
36_index36.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Use prototype
//-------------------------------------------------------------------------------------
// const user1 = {
// firstName: "Manish",
// lastName: "Tomar",
// email:"manishtomar00mt@gmail.com",
// age: 22,
// address: "House Number, Colony, pincode, state",
// about: function(){
// return `${this.firstName} is ${this.age} years old`
// },
// is18: function(){
// return this.age >= 18;
// }
// }
//----------------------------------------------------------------------------------------
//function (that funciton creates object)
//2.) add key value pair
//3.) object ko return krega
const userMethods ={
about: function(){
return `${this.firstName} is ${this.age} years old`;
},
is18: function(){
return this.age >=18;
}
}
//-----------------------------------------------------------------------------------------
function createUser(firstName , lastName , email, age , address){
const user = {}
user.firstName = firstName;
user.lastName = lastName;
user.email = email;
user.age = age;
user.address = address;
// about: function(){
// return `${this.firstName} is ${this.age} years old`
// },
// is18:function(){
// return this.age >= 18;
// }
//another way (method separation method)
user.about = userMethods.about; //reference hai yeh or hum address likh rahe hai userMethods k about method ka
user.is18 = userMethods.is18;
return user;
}
createUser.prototype.about = function(){
return `${this.firstName} is ${this.age} years old and live in ${this.address}`;
};
createUser.prototype.is18 = function(){
return this.age>=18;
};
createUser.prototype.sing = function(){
return 'tun naa na na la la ';
};
const user1 = createUser('manish','Tomar','manishtomar00mt@gmail.com',22, "delhi");
const user2 = createUser('Sonal','Mishra','manishtomar00mt@gmail.com',22, "Bihar");
const user3 = createUser('Varun','Tomar','varuntomar3233@gmail.com',18, "delhi");
console.log(user1);
console.log(user2.about());
// console.log(user3.sing());