File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
part6 (Object-Oriented Programming)/Objects Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ const user = {
11
11
name : "Rafay" ,
12
12
greet ( ) {
13
13
console . log ( `Hello, ${ this . name } ` ) ;
14
- }
14
+ } ,
15
15
} ;
16
16
17
17
const admin = {
@@ -23,6 +23,18 @@ admin.__proto__ = user;
23
23
console . log ( admin . name ) ; // "Rafay"
24
24
admin . greet ( ) ; // Hello, Rafay
25
25
26
+ // Another Example
27
+ function Person ( firstName , lastName ) {
28
+ this . firstName = firstName ;
29
+ this . lastName = lastName ;
30
+ }
31
+ Person . prototype . gender = "Male" ;
32
+
33
+ const person1 = new Person ( "Elon" , "Musk" ) ;
34
+ const person2 = new Person ( "Bill" , "Gates" ) ;
35
+
36
+ console . log ( person2 . gender , person1 . gender ) ; // Male, Male
37
+
26
38
/*
27
39
INFO: Object.getPrototypeOf() and Object.setPrototypeOf()
28
40
you can also get/set protypes programmatically:
@@ -44,4 +56,12 @@ When you access a property:
44
56
This is called Prototype Chain.
45
57
*/
46
58
59
+ /*
60
+ INFO: __proto__
61
+ An object property that points to another object (its prototype).
62
+ Used to inherit from another object.
47
63
64
+ INFO: prototype
65
+ A property of constructor functions (or classes)
66
+ Used to add shared methods/properties to all instances created by new
67
+ */
You can’t perform that action at this time.
0 commit comments