Created
June 5, 2017 10:16
-
-
Save fernandozamoraj/c34f541eb7d2a25f4b3aa9f2b190d5da to your computer and use it in GitHub Desktop.
Prototypal Inheritance
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
function Person(firstname, lastname){ | |
this.firstname = firstname; | |
this.lastname = lastname; | |
} | |
function Teacher(firstname, lastname, subject){ | |
Person.call(this, firstname, lastname); | |
this.subject = subject; | |
} | |
Teacher.prototype = Object.create(Person); | |
Teacher.prototype.constructor = Teacher; | |
console.log(Teacher); | |
console.log(Teacher.prototype); | |
var teacher = new Teacher("John", "Doe", "math"); | |
console.log(teacher); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a quick example of inheritance as I understand it.