Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Created November 22, 2014 09:17
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 alessioalex/042f09cc2e33b996f246 to your computer and use it in GitHub Desktop.
Save alessioalex/042f09cc2e33b996f246 to your computer and use it in GitHub Desktop.
inheritance-0.js
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.getInfoCard = function() {
return this.name + ', ' + this.age + ' years old';
};
var johnny = new Person('John', '25');
console.log(johnny.getInfoCard());
function Student(name, age, university) {
/*...*/
}
var junior = new Student('John', 18, 'MIT');
// console.log(junior instanceof Person);
console.log(junior.getInfoCard());
// bonus points
var junior2 = Student('John', 18, 'MIT');
console.log(junior2.getInfoCard());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment