-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_constructor_function.js
More file actions
83 lines (57 loc) · 1.59 KB
/
object_constructor_function.js
File metadata and controls
83 lines (57 loc) · 1.59 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
/*
// constructor function
function person(name, age, course, exp){
this.name = name
this.age = age
this.course = course
this.exp = exp
}
// creation of object by calling the constructor function with 'new' keyword
const person1 = new person("Sampad", 28, "PhD", 3)
const person2 = new person ("Ram", 23, "MSc", 2)
console.log(person1)
// console.log(person1.name)
console.log(person2)
*/
/*
// adding property to an object
person1.nationality = "Indian"
console.log(person1)
console.log(person2)
*/
/*
// addition of property to the constructor function is not possible the way a new property is added
// to an existing object.
person.nationality = "Indian"
console.log(person1)
console.log(person2)
*/
// To add a new property to a constructor, you must add it to the constructor function:
/*
function person(name, age, course, exp){
this.name = name
this.age = age
this.course = course
this.exp = exp
this.nationality = "Indian"
}
const person1 = new person("Sampad", 28, "PhD", 3)
const person2 = new person ("Ram", 23, "MSc", 2)
console.log(person1)
console.log(person2)
*/
function person(name, age, course, exp, nationality){
this.name = name
this.age = age
this.course = course
this.exp = exp
this.nationality = nationality
}
const person1 = new person("Sampad", 28, "PhD", 3, "Indian")
const person2 = new person ("Ram", 23, "MSc", 2, "Indian")
console.log(person1)
<<<<<<< HEAD
console.log(person2)
=======
console.log(person2)
>>>>>>> 29ec691 (committed)