-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype1.js
More file actions
30 lines (23 loc) · 846 Bytes
/
Copy pathprototype1.js
File metadata and controls
30 lines (23 loc) · 846 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
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
const myFather=new Person("Ram","Nandy",23,"red");
myFather.nationality="Indian" // Adding Property to Object
myFather.name= ()=>{ // Adding method To and Object
return this.firstName + " " + this.lastName;
}
console.log(myFather)
// But we cannot add a new property to an object constructor
Person.nationality = "English"; // This will not work and give undefined
console.log(myFather.nationality);
// The JavaScript prototype property allows you to add new properties to object constructors:
Person.prototype.nationality="Greek"
const myFather2 = new Person("Ram", "Nandy", 23, "red");
console.log(myFather2.nationality)
let a=[1,2];
console.log(a.__proto__);
let b = {};
console.log(b.__proto__);