原型链
以下仅是个人对原型链的理解,如有不对的地方望大佬指出
先来看一下作者总结的一张图,一些含义注释图中都有写出
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/705a8dd5f5e62a22ba4e3892ea129715.png)
结合下面这段代码可以帮助大家理解
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function Person(uname, age) {
this.uname = uname;
this.age = age;
}
Person.prototype.sing = function () {
console.log('追加的方法被调用');
}
var P = new Person('小明', 18);
console.log(P);
console.log(P.__proto__);
console.log(Person.prototype);
console.log(P.__proto__ == Person.prototype);
console.log(Person.prototype.sing());
console.log(Person.prototype.__proto__ === Object.prototype);
console.log(Object.prototype.__proto__);
</script>
</body>
</html>