<html><head><script>
function Pet(){ // Base Class
var owner = "Mrs. Jones";
var gender = undefined;
this.setOwner = function(who) { owner=who; }; //1
this.getOwner = function(){ return owner; }
this.setGender = function(sex) { gender=sex; }
this.getGender = function(){ return gender; }
}
function Cat(){} //subclass constructor
Cat.prototype = new Pet();
Cat.prototype.constructor=Cat;
Cat.prototype.speak=function speak(){
return("Meow"); //2
}; //3
function Dog(){}; //4
Dog.prototype= new Pet();
Dog.prototype.constructor=Dog;
Dog.prototype.speak = function speak(){
return("Woof");
}; //5
</script></head>
<body><script>
var cat = new Cat;
var dog = new Dog;
cat.setOwner("John Doe");
cat.setGender("Female");
dog.setGender("Male");
document.write(
"<br>The cat is a "+ cat.getGender()+ " owned by "
+ cat.getOwner() +" and it says " + cat.speak());
document.write(
"<br>The dog is a "+ dog.getGender() + " "
+ " owned by " + dog.getOwner() + " and it says " + dog.speak());
</script></body>
//1
上記のコードの、//2
、//3
、//4
とマークされた行の右中括弧の後にセミコロンがあるのはなぜ//5
ですか?- いつ実行さ
Cat.prototype = new Pet();
れDog.prototype = new Pet();
ますか。