Created
December 22, 2019 06:00
-
-
Save bhaveshdaswani93/57ddde64387e0a6796b2f244ad1395f0 to your computer and use it in GitHub Desktop.
Understanding classes in javascript
This file contains 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
class Person | |
{ | |
constructor(first_name,last_name) { | |
this.first_name = first_name; | |
this.last_name = last_name; | |
} | |
getFullName() { | |
return `Full Name is: ${this.first_name} ${this.last_name}`; | |
} | |
} | |
let personA = new Person('lorem','ipsum'); | |
let personB = new Person('felis','ullamcorper'); | |
personA.getFullName(); | |
//Output: Full Name is: lorem ipsum | |
// In each instance personA,personB getFullName function is shared means when personA.getFullName() is called, the javascript engine | |
// first will look in personA object if it is not found there then it will look in the personA parent that is Person.prototype from where it get | |
// resolved | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment