I have 2 class: animal(parent) and dog(the 'child' of animal), when I create an object of Animal, and try to alert the name of the animal, I got undefined , and not her real name. Why? (sorry about the double post )
function Animal(name, year){
alert(name);
this.name = name;
this.year = year;
this.age = function (){
var n = new Date().getFullYear();
return n - this.year;
};
}
function Dog(name, year, color, type) {
this.color = color;
this.type = type;
Animal.call(this, name, year);
//override method age of animal
this.age = function (){
var n = new Date().getFullYear();
return (n - this.year) * 7;
};
Dog.prototype.age();
}
Dog.prototype = new Animal();
(This js class named: JsClass.js)
and in HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="JsClass.js"></script>
<script type="text/javascript">
var p1 = new Animal("rex",2008);
</script>
<title>Insert title here</title>
</head>
<body>
</body>
</html>
(using Eclipse)
Thank you!