Skip to content

Instantly share code, notes, and snippets.

@bhaveshdaswani93
Created December 22, 2019 04:43
Show Gist options
  • Save bhaveshdaswani93/de9caed40118103b7ea44f82db2ba254 to your computer and use it in GitHub Desktop.
Save bhaveshdaswani93/de9caed40118103b7ea44f82db2ba254 to your computer and use it in GitHub Desktop.
This gist show an example of constructor function.
let Person = function(first_name,last_name) {
this.first_name = first_name;
this.last_name = last_name;
}
Person.prototype.getFullName = function() {
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