Skip to content

Instantly share code, notes, and snippets.

@camerican
Created October 7, 2017 19:17
Show Gist options
  • Save camerican/671dcc2a54f56b214cb67449ece0afbb to your computer and use it in GitHub Desktop.
Save camerican/671dcc2a54f56b214cb67449ece0afbb to your computer and use it in GitHub Desktop.
Mahima OO Code Review
//1.
function Multiplier(){
this.newValue = 1;
this.multiply = function(num){
this.newValue = (this.newValue * num);
return this.cValue; // cValue is undefined!!
}
this.getCurrentValue = function () {
return this.newValue;
}
}
//2.
function Album () {
this.name = name; // name is undefined!!
this.photoAlbum = [];
}
//2.
Album.prototype.addPhoto = function (src,location) {
this.photoAlbum.push(new Photo(src,location))
};
Album.prototype.listPhoto = function( ) {
return this.photoAlbum.join(“, “) // careful of curly quotes!! they will cause errors
};
Album.prototype.getPhoto = function (i) {
return this.photoAlbum[i]
};
// 3.
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;
}
// what is this function?? Looks like a constructor being attached to the Person
// prototype... but why?
Person.prototype.teacher = function (gender, name, age, grade, activity) {
this.activity = Teacher; // Teacher is undefined... looks like it's meant to be
// a reference to the Teacher constructor
// but why save a reference to the constructor as an attribute
// of a Person?
Person.call(this, name, age, grade);
this.gender = function() { // you're setting gender to be a function...
var prefix;
if (gender == m || gender == male) || gender == Male){ // problem here as m, male, and Male are all undefined
prefix =“Mr.” // did you mean for them to be strings?
} else {
prefix = “Mrs.” // watch out for curly quotes. what are you doing with prefix?
}
}
}
teacher.prototype = Object.create(Person.prototype) // Watch capitalization!
};
// student should probably have its own constructor
Person.prototype.student = function (name, age, grade, activity) {
this.activity = Student;
Person.call(this, name, age, grade);
};
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