Artificial intelligent assistant

Animal.call(this, "dog"); は何をしているのでしょうか? なぜ必要? function Dog(name, breed){ Animal.call(this, "dog"); this.name = name; this.breed = breed; } Animal.call(this, "dog"); … <

Animal `this.type`


//

function Animal(type){
this.type = type;
}
Animal.isAnimal = function(obj, type){
if(!Animal.prototype.isPrototypeOf(obj)){
return false;
}
return type ? obj.type === type : true;
};
function Dog(name, breed){
// ↓
// Animal.call(this, "dog");

this.name = name;
this.breed = breed;
}
Object.setPrototypeOf(Dog.prototype, Animal.prototype);
Dog.prototype.bark = function(){
console.log("ruff, ruff");
};
Dog.prototype.print = function(){
console.log("The dog " + this.name + " is a " + this.breed);
};
Dog.isDog = function(obj){
return Animal.isAnimal(obj, "dog");
};

var sparkie = new Dog("Sparkie", "Border Collie");
// true
document.write('Dog.isDog(sparkie): ' + Dog.isDog(sparkie));

`super(hoge)` Javascript `Function.prorotype.call()` `new Animal("dog")` `this`

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 71a5edb901304f4ce6b75df135e1669c