Created
November 22, 2014 09:17
-
-
Save alessioalex/042f09cc2e33b996f246 to your computer and use it in GitHub Desktop.
inheritance-0.js
This file contains 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
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