Skip to content

Instantly share code, notes, and snippets.

@jfernandez
Last active December 15, 2015 20:41
Show Gist options
  • Save jfernandez/5320608 to your computer and use it in GitHub Desktop.
Save jfernandez/5320608 to your computer and use it in GitHub Desktop.
Javascript constructors and the prototype object
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.speak = function () {
return "Hello, my name is " + this.name;
}
Person.prototype.canVote = function() {
return this.age >= 18;
}
person = new Person("John Doe", 30)
person.speak();
person.canVote();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment