Created
December 22, 2019 04:43
-
-
Save bhaveshdaswani93/de9caed40118103b7ea44f82db2ba254 to your computer and use it in GitHub Desktop.
This gist show an example of constructor function.
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
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