I'm somewhat new to JavaScript. I know that you should use prototype to implement inheritance between objects, but I tried the following and it worked perfectly (using Visual Studio 2012). What am I doing wrong?
function Person(firstname, lastname, age, eyecolor) {
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
this.eyecolor = eyecolor;
this.name = function() {
return this.firstname + " " + this.lastname;
}
}
function Student(firstname, lastname, age, eyecolor, level) {
this.level = level;
Person.call(this, firstname, lastname, age, eyecolor);
}
var per = new Person("Abe", "Lincoln", 45, "green");
var obj = new Student("Abe", "Lincoln", 45, "green", "senior");
When I examine obj, it has properties for Person and for Student, and I can call obj.name() to get "Abe Lincoln". Even in the Visual Studio immediate window, I can see all of the properties as siblings of one another, as I would expect. But I am not using prototype, so obviously this is not right.
Set me straight please :)
Thanks in advance!