Created
June 19, 2020 12:35
-
-
Save adrianmarkperea/84202a681ce96953b44a428d176ce78a 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