File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const user = {
2+ username : "knq" ,
3+ loginCount : 8 ,
4+ signedIn : true ,
5+
6+ getUserDetails : function ( ) {
7+ // console.log("Got user details from database");
8+ console . log ( `Username: ${ this . username } ` ) ;
9+ console . log ( this ) ;
10+ }
11+ }
12+
13+ console . log ( user . username ) ;
14+ console . log ( user . getUserDetails ( ) ) ;
15+
16+
17+ //Constructor -> new keyword
18+ // const promiseOne = new Promise();
19+ // const date = new Date();
20+ function User ( username , loginCount , isLoggedIn ) {
21+ this . username = username ;
22+ this . loginCount = loginCount ;
23+ this . isLoggedIn = isLoggedIn ;
24+ this . greeting = function ( ) {
25+ console . log ( `Welcome ${ this . username } ` ) ;
26+ }
27+ return this ;
28+ }
29+ const userOne = User ( "knq" , 12 , true ) ;
30+ const userTwo = User ( "Kalp" , 11 , false ) ;
31+ console . log ( userOne ) ;
32+ console . log ( userOne . constructor ) ;
33+ console . log ( userTwo ) ;
34+ // new object was created
35+ // constructor function was called
36+ // this keyword inject the arguments
37+ // function
You can’t perform that action at this time.
0 commit comments