ioksan Posted February 23, 2015 Share Posted February 23, 2015 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 persoanafunction persoana(nume, prenume, cnp) { this.nume = nume; this.prenume = prenume; this.cnp = cnp;}// definim o metoda pentru afisarea numelui completpersoana.prototype.arataNume = function() {return this.nume + " " + this.prenume;};// definim o metoda pentru afisarea cnp-uluipersoana.prototype.arataCNP = function() {return this.cnp;};// Definim clasa studentfunction student(nume, prenume, cnp, nr_carnet, medie) {// constructor parintepersoana.call(this, nume, prenume, cnp);// proprietati publice si proprii pentru student this.nr_carnet = nr_carnet; this.medie = medie;}// Mostenim de la clasa persoanastudent.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 carnetstudent.prototype.arataNume = function() {return "Student: " + this.nume + " " + this.prenume + " - Numar carnet: " + this.nr_carnet;};// Definire metoda pentru afisare medie studentstudent.prototype.medieStudent = function() {return this.medie;};// instantiem si rulam metodelevar 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.org/learn/class-inheritance.html" Link to comment Share on other sites More sharing options...
davej Posted February 23, 2015 Share Posted February 23, 2015 You need to find someone who uses Prototype.js. You might want to look at... https://groups.google.com/forum/#!forum/prototype-scriptaculous http://prototypejs.org/discuss It looks like the syntax is more like "classical" inheritance with "initialize" being the constructor function. See this example... http://api.prototypejs.org/language/Class/prototype/addMethods/ Link to comment Share on other sites More sharing options...
Ingolme Posted February 23, 2015 Share Posted February 23, 2015 It's his homework. His teacher asked him to use Prototype.js to create classes. I believe the very page he linked to describes how to do it better than I could. If that's not enough, he should check any resources his teacher gave him. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now