Hy guys.
I have a homework that says something like that:
"Create a class called Person with the attributes id, name, surname.
Create another class called Student that inherits the class Persons and
also has it`s own two attributes: id_card and average.
Implement at least 2 methods in Person class and 1 method in Student class.
Call all 3 methods after creating the instance of Student class."
I managed to create this:
"<html>
<head>
<script>
// Definim clasa persoana
function persoana(nume, prenume, cnp) {
this.nume = nume;
this.prenume = prenume;
this.cnp = cnp;
}
// definim o metoda pentru afisarea numelui complet
persoana.prototype.arataNume = function() {
return this.nume + " " + this.prenume;
};
// definim o metoda pentru afisarea cnp-ului
persoana.prototype.arataCNP = function() {
return this.cnp;
};
// Definim clasa student
function student(nume, prenume, cnp, nr_carnet, medie) {
// constructor parinte
persoana.call(this, nume, prenume, cnp);
// proprietati publice si proprii pentru student
this.nr_carnet = nr_carnet;
this.medie = medie;
}
// Mostenim de la clasa persoana
student.prototype = Object.create(persoana.prototype);
// Definim o metoda pentru clasa student metoda prin care de fapt
suprascriem metoda parinte arataNume si afisam in plus si numarul de
carnet
student.prototype.arataNume = function() {
return "Student: " + this.nume + " " + this.prenume + " - Numar carnet: " + this.nr_carnet;
};
// Definire metoda pentru afisare medie student
student.prototype.medieStudent = function() {
return this.medie;
};
// instantiem si rulam metodele
var unStudent = new student("xyz","abc","7432943929393", "122", "8");
alert(unStudent.arataNume());
alert("CNP student: " + unStudent.arataCNP());
alert("Medie student: " + unStudent.medieStudent());
</script>
</head>
<body>
</body>
</html>"
The problem is that my professor refused my homework because I didn`t use PrototypeJS.
Can you help me converting this code? I didn`t understood his request and by browsing this page I could`t understand much:
"http://prototypejs.o...nheritance.html"
Thanks.