Created
June 19, 2020 12:34
-
-
Save adrianmarkperea/5784f78e00b3e8cf218ab2860625a256 to your computer and use it in GitHub Desktop.
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
function Person(firstName, lastName) { | |
// 1. An implicit object is created that we can reference with `this` | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
// 2. The resulting instance has a copy of the | |
// constructor function's prototype property | |
// inside its own prototype. | |
Person.prototype.fullName = function() { | |
console.log(`${firstName} ${lastName}`); | |
} | |
const personA = new Person('Adrian', 'Perea'); | |
const personB = new Person('Ben', 'Halpern'); | |
personA.fullName() // Adrian Perea | |
personB.fullName() // Ben Halpern |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment