Last active
November 3, 2019 07:37
-
-
Save AkashRajvanshi/9969907cb40fbcac41d2a34154bf0c87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example Of Constructor Function | |
| function User(firstName, lastName, age) { | |
| this.firstName = firstName | |
| this.lastName = lastName | |
| this.age = age | |
| this.getDetails = function () { | |
| console.log(`I am ${this.firstName} ${this.lastName}`) | |
| } | |
| } | |
| // Creating a new person with 'new' keyword | |
| const akash = new User('Akash', 'Rajvanshi', 22) | |
| console.log(akash) // User { firstName: 'Akash', lastName: 'Rajvanshi', age: 22, getDetails: [λ] } | |
| console.log(akash.getDetails()) // I am Akash Rajvanshi | |
| // New User | |
| const abha = new User('Abha', 'Rajvanshi', 58) | |
| console.log(abha) // User { firstName: 'Abha', lastNam: 'Rajvanshi', age: 58, getDetails: [λ] } | |
| console.log(abha.getDetails()) // I am Abha Rajvanshi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment