当前位置:网站首页>一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)
一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)
2022-07-02 11:21:00 【名字还没想好*】
一、先上图

二、prototype、proto、constructor规则
规则一:实例没有prototype,实例的constructor指向构造函数,实例的__proto__指向上一层的原型(也就是构造函数的prototype)。
规则二 :Object、构造函数、Function都是Function的实例。
实例:结合这两条规则,图中的f1是Foo的实例,Foo、Object、Function均为Function的实例。指向就非常明确了。
规则三:函数的原型的__proto__指向上一层的原型(也就是Fun.prototype.proto 指向Object.prototype)
规则四:函数的原型的constructor指向函数本身(可以理解为prototype和constructor抵消了)
实例:结合三四规则,下图的也走通了。
三、上代码
function Fun(){
}
const f1 = new Fun()
console.log(f1.constructor === Fun)
console.log(f1.__proto__ === Fun.prototype)
console.log(Function.prototype === Function.__proto__)
console.log(Fun.prototype.constructor === Fun)
console.log(Fun.prototype.__proto__ === Function.__proto__.__proto__)
console.log(Fun.constructor.__proto__ === Function.prototype)
console.log(Object.constructor === Function)
console.log(Function.constructor === Function)
console.log(Function.prototype.__proto__ === Object.prototype)
console.log(Object.prototype.__proto__ === null)
//结果全部为true
总结:当图中的关系已经印在脑海中的时候,可以尝试自己写出三者之间的转换等式,以及各种嵌套。
例如:new Fun().constructor.proto.proto === Object.prototype
边栏推荐
- 测试框架TestNG的使用(二):testNG xml的使用
- PTA题库 ===>复数四则运算,一帮一,考试座位号(7-73)
- PyQt5_QScrollArea内容保存成图片
- uni-app中使用computed解决了tab切换中data()值显示的异常
- TeamTalk源码分析之win-client
- Penetrate the remote connection database through the Intranet
- Generally speaking, if the error of inconsistent tab and space occurs frequently
- < schematic diagram of oral arithmetic exercise machine program development> oral arithmetic exercise machine / oral arithmetic treasure / children's math treasure / children's calculator LCD LCD driv
- 大顶堆、小顶堆与堆排序
- 数据湖(十一):Iceberg表数据组织与查询
猜你喜欢

Yolov3 & yolov5 output result description

The conference on the growth of all things was held in Hangzhou, and dangbei was selected into the top 100 list of future unicorns in China in 2022

Penetrate the remote connection database through the Intranet

Pychart connects to the remote server

抓包工具fiddler学习

Fabric.js 上划线、中划线(删除线)、下划线

Qt新建项目

buuctf-pwn write-ups (7)

STM32-DAC实验&高频DAC输出测试

博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
随机推荐
测试框架TestNG的使用(二):testNG xml的使用
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Convolutional neural network (Introduction)
1、编辑利器vim
Fabric.js 元素被选中时保持原有层级
P1042 [noip2003 popularization group] Table Tennis
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
Fabric. JS zoom canvas
Qt原代码基本知识
数据库连接池和数据源
docker mysql
Adhere to the foundation of 20 minutes go every day II
NLA自然语言分析实现数据分析零门槛
uniapp自动化测试学习
Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
跨服务器数据访问的创建链接服务器方法
Daily learning 2
每日学习3
STM32-DAC实验&高频DAC输出测试
P1908 reverse sequence pair

