HYFClass
should have a method thatreturn
s all the name of themember
s.HYFClass
should have a method thatreturn
s onlyStudents
and one thatreturn
s onlyTeachers
Last active
August 10, 2017 19:16
-
-
Save M3kH/4115771899b07d7a668fc9266b35fe08 to your computer and use it in GitHub Desktop.
OOP - HYF Class
This file contains 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( lastName, name ){ | |
this.lastName = lastName; | |
this.name = name; | |
this.getLastName = function(){ | |
return this.lastName || 'Not defined'; | |
}; | |
this.getName = function(){ | |
return this.name || 'Not defined'; | |
} | |
} | |
function Teacher( lastName, name ){ | |
Person.call(this, lastName, name); | |
return this; | |
} | |
function Student(lastName, name){ | |
Person.call(this, lastName, name); | |
this.homework = []; | |
return this; | |
} | |
function HYFClass(){ | |
this.members = []; | |
this.addMember = function( instanceOfPerson ){ | |
this.members.push( instanceOfPerson ); | |
} | |
this.getAllMemberName = function(){ | |
// TODO | |
} | |
this.getAllMemberLastName = function(){ | |
for(var k=0; k<this.members.length; k++){ | |
// FIX to return values | |
console.log(this.members[k].getLastName()); | |
} | |
} | |
this.getStudents = function(){ | |
for(var k=0; k< this.members.length; k++){ | |
if(this.members[k] instanceof Student) | |
// TODO | |
} | |
} | |
this.getTeachers = function(){ | |
// TODO | |
} | |
} | |
var members = [ | |
{name: 'Mauro', lastName: 'Mandracchia', type: 'teacher'}, | |
{name: 'Ali', lastName: 'Barakat', type: 'student'} | |
]; | |
var JS3 = new HYFClass(); | |
for(var k=0; k<members.length; k++){ | |
var member = members[k]; | |
if(member.type === 'teacher'){ | |
JS3.addMember( new Teacher(member.lastName, member.name) ); | |
}else{ | |
JS3.addMember( new Student( member.lastName, member.name) ) | |
} | |
} | |
JS3.getAllMemberLastName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment