老师,是这样写的吗?不太明白为什么cat要写一个空方法在那里?
prototype属性不能定义在方法中?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>6-4编程</title>
</head>
<body>
<script>
function Animal(name,num){//父
this.name=name;
this.num=num;
}
function Cat(){} //子
//原型方式继承Animal
Cat.prototype=new Animal("猫咪",10);
Cat.prototype.info=function(){
alert(this.name+"---"+this.num);
}
var c=new Cat();
c.info();
</script>
</body>
</html>
21
收起
正在回答 回答被采纳积分+1
2回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧