当前位置:网站首页>js中的原型与原型链
js中的原型与原型链
2022-08-06 23:40:00 【taotu_tao】
function Person(){}1、prototype(有且仅有函数有该属性)
1、 函数有prototype属性,该属性指向显示原型、原型对象
2、 原型对象:拥有prototype属性的对象,在定义函数时自动创建

2、constructor
原型对象的constructor属性,指向构造函数本身

3、__proto__(引用类型都有该属性)
1、 原型对象有__proto__属性(隐式原型),该属性指向了Object的显示原型

2、 Object也有__proto__属性,因为Object是顶级对象,所以这时指向null

3、Object的构造函数


4、实例化对象
构造函数的实例有__proto__属性,并且该属性指向原型对象
也就是说对象的隐式原型指向构造函数的显式原型,两者等价,所以有

const p = new Person()
console.log(p);
下面是本文章所出现的代码
<script>
function Person() {
}
console.log('-------------Person.prototype-----------');
console.log(Person.prototype);// 原型对象
console.log('-------------Person.prototype.constructor-----------');
console.log(Person.prototype.constructor);// Person() {}
console.log('-------------Person.prototype.__proto__-----------');
// 原型对象的隐式原型
console.log(Person.prototype.__proto__);//Objext
console.log('-------Person.prototype.__proto__.constructor-------');
console.log(Person.prototype.__proto__.constructor);// Objext()
console.log('-------------Person.prototype.__proto__.__proto__-----------');
// 原型对象的隐式原型的隐式原型
// 原型链 最后指向null
console.log(Person.prototype.__proto__.__proto__);// null
const p = new Person()
console.log(p);// Person {}
console.log('-------p.__proto__ == Person.prototype-----');
console.log(p.__proto__ == Person.prototype);// true
</script>边栏推荐
- 【超好懂的比赛题解】2022 Jiangsu Collegiate Programming Contest 比赛题解
- 轻松完成接口测试及接口文档
- 复制天猫的宝贝上传到淘宝,SKU自定义属性值没有复制过来是什么原因?
- php 三维数组根据某个键合并并累加他们的值
- 微信小程序跟qq小程序不能用一个云开发吗?
- 那些舍不得删除的 MP3--批量修改mp3的ID3tag
- Arrangement of knowledge points in public relations
- 灵活好用的sql monitoring 脚本 part5
- golang使用josn.Unmarshal报错:unexpected end of JSON input
- 安静的思考
猜你喜欢
随机推荐
What about online stock account opening?Is it safe to open an account?
公共关系与人际交往能力
Public Relations and Interpersonal Skills
【超好懂的比赛题解】2022 Jiangsu Collegiate Programming Contest 比赛题解
WPF双滑块控件以及强制捕获鼠标事件焦点
[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.4 Introduction to Anti-Aliasing
uuid 数据处理32位,16位
Record the days we went through together
Those MP3s that are reluctant to delete--modify the ID3tag of mp3 in batches
three.js 第五十五用 给shader传递uniform注意事项
最长偶串的长度
时间复杂度和空间复杂度
GoLang system design
长安欧尚z6idd的智能性如何?采用了整套主被动安全保护措施
浅谈 API 网关
Promise的点点滴滴
Zabbix5.0部署+监控服务,图文详解,亲测有效!!
Julia两天极速入门学习笔记
阿帽的新画
php three-dimensional array merge and accumulate their values according to a key









