Converting classical JS to PrototypeJS

Skip to first unread message


Feb 23, 2015, 10:28:10 AM2/23/15

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:


// 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, 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("CNP student: " + unStudent.arataCNP());
alert("Medie student: " + unStudent.medieStudent());



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:




Dec 28, 2015, 1:59:04 PM12/28/15
to Prototype &
Ioksan i have the same homework,did you find the solution?and can you post it her?
Reply all
Reply to author
0 new messages