Skip to content

Instantly share code, notes, and snippets.

@jwmcpeak
Created September 11, 2012 20:12
Show Gist options
  • Save jwmcpeak/3701666 to your computer and use it in GitHub Desktop.
Save jwmcpeak/3701666 to your computer and use it in GitHub Desktop.
JS Inheritence
var Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
Person.prototype.sayHi = function() {
return "Hello there!";
};
var Student = function(firstName, lastName, matriculatoryStatus) {
Person.call(this, firstName, lastName);
this.matriculatoryStatus = matriculatoryStatus;
};
Student.prototype = Object.create(Person.prototype);
Student.prototype.sayHiToTeacher = function() {
return "Hi, teacher!";
};
var student = new Student("John", "Doe", "Freshman");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment