-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproto3.js
More file actions
62 lines (42 loc) · 1.55 KB
/
proto3.js
File metadata and controls
62 lines (42 loc) · 1.55 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
function Person(){
this.name = 'Aakash',
this.hobby = 'Hacking',
this.job = 'Yes'
}
// add a property
Person.prototype.language = 'Hindi';
// create an object
var person2 = new Person();
Person.prototype.hobby = 'Coding';
console.log(Person.prototype.hobby === person2.__proto__.hobby)
console.log("Will we see Coding: " + person2.hobby);
console.log("Person2.language " + person2.language);
// Changing the property value of Prototype
Person.prototype.hobby = 'Coding';
var person3 = new Person();
Person.prototype.language = 'Coding';
console.log("person2.language " + person2.language);
/*
Person.prototype = {'language': "Test",
"toString": ()=>{while(true){}}
}
*/
Person.prototype = {'language': "Test",
__proto__: {__proto__: {"toString": "x"}}
}
var person7 = new Person();
//person7.__proto__.__proto__.toString = "x"
console.log(person7)
//person3.__proto__ = {'language': "Test",
//"toString": ()=>{while(true){}}}
console.log("Are protos equal" + (person2.__proto__ === person3.__proto__));
console.log(Object.prototype.toString) // Object prototype's toString method is not overridden
console.log(person2.__proto__.toString) // Object prototype's toString method is not overridden
console.log(person7.toString()) //Only the Person prototype's toString method is overridden but that may be enough
console.log(person3.language);
console.log(person2.hobby)
console.log(person2.language);
Person.__proto__.toString = ()=>{alert("polluted")}
console.log(person3.toString())
console.log(person2)
console.log("Stuck?")