File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,3 +15,40 @@ counter1.incrementCounter();
1515counter1 . incrementCounter ( ) ;
1616counter1 . incrementCounter ( ) ;
1717counter1 . decrementCounter ( ) ;
18+
19+ console . log ( "---------------------" ) ;
20+
21+ function Person ( ) {
22+ //define properties
23+ this . name = "Joker" ;
24+ this . age = 25 ;
25+
26+ this . getName = function ( ) {
27+ // "this" here refers to the "Person" constructor.
28+ // "this.name" is like "Person.name".
29+ return `Hello, my name is ${ this . name } .` ;
30+ } ;
31+ }
32+
33+ //Create object with Person constructor
34+
35+ const personOne = new Person ( ) ;
36+ const personTwo = new Person ( ) ;
37+
38+ console . log ( personOne . name ) ;
39+ console . log ( personOne . getName ( ) ) ;
40+
41+ personOne . gender = "Male" ;
42+ console . log ( personOne . gender ) ;
43+ console . log ( personTwo . gender ) ; // gender only exists only on personOne
44+
45+ personTwo . height = 1.8 ;
46+ console . log ( "Height:" , personTwo . height ) ;
47+ console . log ( "Height:" , personOne . height ) ;
48+
49+ const personThree = new Person ( ) ;
50+
51+ personThree . getAge = function ( ) {
52+ return `Age: ${ this . age } ` ;
53+ } ;
54+ console . log ( personThree . getAge ( ) ) ;
You can’t perform that action at this time.
0 commit comments