Skip to content

Instantly share code, notes, and snippets.

@camerican
Created October 7, 2017 19:06
Show Gist options
  • Save camerican/2e96f25d2c484eaabe9cb448cf94574c to your computer and use it in GitHub Desktop.
Save camerican/2e96f25d2c484eaabe9cb448cf94574c to your computer and use it in GitHub Desktop.
Sherill OO Code Review
// Create a prototypical Person object.
// From this object,
// --> Extend a Teacher object and a Student object.
// --> Each of these objects should have attributes and methods pertinent to what they describe.
// --> Also create a School object that should be able to store instances of students and teachers.
// --> Make sure to write code afterwards that creates instances of these objects to make sure that what you’ve written works well and you’re able to store the necessary data in each object.
function School(){
this.class = [];
}
School.prototype.addMember = function (person) {
this.class.push(person)
return this;
};
function Person(name, age, grade){
this.name = name;
this.age = age;
this.grade= grade;
}
// below you're creating a method teacher on the Person prototype... so each instance of a person
// will be able to call a teacher function.
Person.prototype.teacher = function (gender, name, age, grade, activity) {
this.activity = Teacher; // why is an activity attribute being set to the Teacher constructor?
Person.call(this, name, age, grade);
this.gender = function() {
var prefix;
if (gender == m || gender == male || gender == Male) { // you probably want 'm' 'male' and 'Male' too all be strings!
prefix ="Mr." // right now they're all undefined variables
} else {
prefix = "Mrs." // you're setting a prefix varaible, but don't appear to be returning it or doing anything with it
}
}
}
function Teacher( firstName, lastName, email ) {
this.email = email;
Person.call(this, firstName, lastName); // you're passing in lastName as age to the Person constructor... Whoops!!
}
teacher.prototype = Object.create(Person.prototype) // watch capitalization!! Teacher.prototype
Person.prototype.student = function (name, age, grade, activity) {
this.activity = Student;
Person.call(this, name, age, grade); // nice
};
student.prototype = Object.create(Person.prototype) // watch capitalization!! Student.prototype
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment