Skip to content

Instantly share code, notes, and snippets.

@bhaveshdaswani93
Created December 22, 2019 06:00
Show Gist options
  • Save bhaveshdaswani93/57ddde64387e0a6796b2f244ad1395f0 to your computer and use it in GitHub Desktop.
Save bhaveshdaswani93/57ddde64387e0a6796b2f244ad1395f0 to your computer and use it in GitHub Desktop.
Understanding classes in javascript
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