Answer the question
In order to leave comments, you need to log in
I can't figure out OOP constructors. Why don't they work?
Now I'm going through OOP JavaScript'a. But for some reason the constructors don't work. The reason for me, as a beginner, is incomprehensible. What is the problem? Here is the code:
<script type='text/javascript'>
function Automobile(color, model, year, manufact)
{
this.color = color + " " || "white";
this.model = model + " "|| "A1";
this.year = year + " " || "2000";
this.manufact = manufact + " " || "Toyota";
function autoInfo ()
{document.write(this.manufact + this.model + this.year);}
function autoColor()
{document.write(color);}
}
function driver (color, model, year, manufact, name, experiance)
{
this.base = Automobile;
this.base(color, model, year, manufact);
this.name = name + " " || "Vasiliy";
this.experiance = experiance + " " || 1;
function driverinfo()
{document.write(this.name + ": experiance " + this.xperiance + "year");}
}
vlad = new driver ("Red", "Skylane", "Nissan", "Vladislav", 5);
vlad.autoInfo();
vlad.autoColor();
document.write("<br/>");
vlad.driverinfo();
</script>
Answer the question
In order to leave comments, you need to log in
driver
Method autoInfo()
B
has function driver() {...}
no definition this.autoInfo
.
Learn to look in the browser console for JavaScript errors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question