请问理解是否正确
来源:6-1 原型继承
蛤小蛤
2019-11-10 19:05:54
<!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>Document</title>
</head>
<body>
<script>
function animals(name, age) {
this.name = name;
this.age = age;
}
animals.prototype.say = function() {
alert("你好我是动物");
};
function cat() {}
cat.prototype = new animals("xiaomao",6);
cat.prototype.hi = function() {
alert("你好我是小猫");
};
var c = new cat();
c.say();
alert(c.name);
c.hi();
// 原型链
// c.__proto__ = cat.prototype = p1.__proto__= animals.prototype
</script>
</body>
</html>1回答
同学你好,是想要问如下注释的代码理解的对吗?

首先=表示赋值,判断是否相等要使用==或者===。同学如上理解的前一半是对的,即c.__proto__ ===cat.prototype。
而animals.prototype与前两个是不相等的,这是因为cat的原型对象是animals的实例,所以 cat.prototype 不等于 animals.prototype。

如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
相似问题