Skip to content

Instantly share code, notes, and snippets.

@adrianmarkperea
Created June 19, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmarkperea/5784f78e00b3e8cf218ab2860625a256 to your computer and use it in GitHub Desktop.
Save adrianmarkperea/5784f78e00b3e8cf218ab2860625a256 to your computer and use it in GitHub Desktop.
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