Skip to content

Instantly share code, notes, and snippets.

@fernandozamoraj
Created June 5, 2017 10:16
Show Gist options
  • Save fernandozamoraj/c34f541eb7d2a25f4b3aa9f2b190d5da to your computer and use it in GitHub Desktop.
Save fernandozamoraj/c34f541eb7d2a25f4b3aa9f2b190d5da to your computer and use it in GitHub Desktop.
Prototypal Inheritance
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);
@fernandozamoraj
Copy link
Author

This is a quick example of inheritance as I understand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment