-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCostructorFunctions.js
More file actions
104 lines (77 loc) · 2.6 KB
/
CostructorFunctions.js
File metadata and controls
104 lines (77 loc) · 2.6 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// // this and function => object
// // string literal
// const em1 = {
// name :"abc",
// lastName: 'xyz'
// }
// const emp12 = {
// name: "abc2",
// lastName: 'xyz2'
// }
// const emp31 = {
// name: "ABC2",
// lastName: 'xyz3'
// }
// // constructor Function
// function Employee (name , lastName) {
// console.log("this as first" , this)
// this.name = name,
// console.log("this as second" , this)
// this.lastName = lastName
// console.log("this=>>" , this)
// }
// const empl1 = new Employee("Gilkrist" ,"Jain" ); // emp1 will be reference with given parameter
// const emp2 = new Employee("Vishal" , "Sharma");
// console.log("em1=> " , empl1)
// console.log("em2=> " , emp2)
// const empl3 = new Employee("Vishal" ,"sharma");
// console.log(empl3)
// // what is the difference b/w creating the object using literal and constructor
// // everytime you will create the object using constructor that will be always unique if you add modify anything that will not impact its parent
// // in the object literal object are not unique and they are sinleton and if you modify child object that will impact the properties of the parent object
// // Can we create constructor function using the arrow functions ??
// const data = {
// name: "Vishal"
// }
// let number = new Number(10); // let a = 10;
// let object = new Object({name: "Vishal" , lastName: ""}); // multi instance
// let string = new String("name"); // let s = "name";
// let boolean = new Boolean(true); // let check = true
// const employeeArrow = ()=> {
// this.name = "Hello";
// console.log(this)
// }
// const emparrow = new employeeArrow(); // this line will throw error because here employeeArrow will not work as the constructor function
// console.log(emparrow)
// window
function Employee(name, lastName) {
// this => {}// automatically this = {}
this.firstName = name;
this.lastName = lastName;
this.printName = function () {
console.log(this.name, this.lastName); // vishal
};
}
const emp = new Employee("Vishal", "Sharma");
const emp1 = new Employee("chetan"); // Employee function is working as a constructor function
console.log("emp", emp.printName()); //
console.log("emp", emp);
// console.log("Employee", Employee()); // here normal function behaviour
// call bind apply
// it used for creating object
// ways to create object
// object literal =>
const data = {
name: "Vishal",
};
//
// const c = data;
// c.name = "Chandan";
// a =123
// const a = new Number(123)
// a =123
// const a = new String(123)
// a =123
// const a = new Number(123)
// a =123
// const a = new Boolean(123)