Last active
June 5, 2017 15:48
-
-
Save getdave/a39175e3d33dc877f56c63e389f5f028 to your computer and use it in GitHub Desktop.
Constructor Functions in JavaScript
This file contains hidden or 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
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