-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path75CreateFunctionsToCreateMultipleObjects.js
59 lines (48 loc) · 1.61 KB
/
75CreateFunctionsToCreateMultipleObjects.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
// creating functions to create multiple objects
// proto , prototype , class --> will learn later
// normal way
// const user = {
// firstName: "Abhishek",
// lastName: "Singh",
// email: "singhabhishek@gmail.com",
// age: 18,
// address: "House Number, Colony, pincode, state",
// about: function(){
// return `${this.firstName} is ${this.age} years old.`;
// },
// is18: function(){
// return this.age >= 18;
// }
// }
// const aboutUser = user1.about();
// console.log(aboutUser);
// what if we needs millons of the user data then what we will do
// hum bar bar user ki data ko input to nahi karenge so that's why
// we will create function which will take user info data as inputs
// these is best way
// 1). function(that function create object)
// 2). add key value pair
// 3). object ko return krega
function createUser(firstName, lastName, email, age, address){
const user = {};
user.firstName = firstName;
user.lastName = lastName;
user.email = email;
user.age = age;
user.address = address;
user.about = function(){
return `${this.firstName} is ${this.age} years old.`;
}
user.is18 = function(){
return this.age >= 18;
}
return user;
}
const user1 = createUser('Abhishek', 'Singh', 'singh@gmail.com', '18', 'varanasi uttar pradesh');
console.log(user1);
const is18 = user1.is18();
console.log(is18); // true
const about = user1.about();
console.log(about); // Abhishek is 18 year old.
// in these approach also have so setback(kameeyaa bhut hai esh me)
// so will keep inproving it in next file(76).