Skip to content

Instantly share code, notes, and snippets.

@moisescastillo
Created July 19, 2020 21:59
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 moisescastillo/a1ef679a36820a5eed632a9042df4d8b to your computer and use it in GitHub Desktop.
Save moisescastillo/a1ef679a36820a5eed632a9042df4d8b to your computer and use it in GitHub Desktop.
Javascript modifying prototypes
function Person(name) {
this.name = name;
this.greeting = function() {
console.log(`Hi I'm ${this.name}`);
}
}
let person1 = new Person('Peter');
let person2 = new person1.constructor('Sarah');
Person.prototype.farewell = function() {
console.log(`${this.name}: Bye for now!`);
}
person1.farewell();
// -> "Peter: Bye for now!"
person2.farewell();
// -> "Sarah: Bye for now!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment