Skip to content

Instantly share code, notes, and snippets.

@getdave
Last active June 5, 2017 15:48
Show Gist options
  • Save getdave/a39175e3d33dc877f56c63e389f5f028 to your computer and use it in GitHub Desktop.
Save getdave/a39175e3d33dc877f56c63e389f5f028 to your computer and use it in GitHub Desktop.
Constructor Functions in JavaScript
const Person = function(name) {
this.name = name; // set instance property
}
// Define "shared" methods on prototype property
Person.prototype.greet = function() {
console.log(`Hello ${this.name}!`);
}
const dave = new Person('David');
dave.greet(); // --> "Hello David!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment