当前位置:网站首页>Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
2022-07-02 14:35:00 【I haven't figured out the name yet*】
One 、 First map
Two 、prototype、proto、constructor The rules
Rule one : Instance does not prototype, Example of constructor Pointing constructor , Example of __proto__ Point to the prototype of the upper layer ( That is, the constructor prototype).
Rule 2 :Object、 Constructors 、Function All are Function Example .
example : Combine these two rules , In the picture f1 yes Foo Example ,Foo、Object、Function Are all Function Example . The direction is very clear .
Rule three : The prototype of the function __proto__ Point to the prototype of the upper layer ( That is to say Fun.prototype.proto Point to Object.prototype)
Rule 4 : The prototype of the function constructor Point to the function itself ( It can be understood as prototype and constructor Offset )
example : Combine the three four rules , The figure below also goes through .
3、 ... and 、 Code up
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)
// The results are all true
summary : When the relationship in the picture has been printed in my mind , Try to write the transformation equation between the three by yourself , And various nesting .
for example :new Fun().constructor.proto.proto === Object.prototype
边栏推荐
猜你喜欢
How kaggle uses utility script
Do you know that there is an upper limit on the size of Oracle data files?
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
kaggle如何使用utility script
[to be continued] [UE4 notes] l5ue4 model import
Fabric.js 缩放画布
There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '
大顶堆、小顶堆与堆排序
Federated Search: all requirements in search
taobao.trade.memo.add( 对一笔交易添加备注 )接口,淘宝店铺插旗接口,淘宝订单插旗API接口,oAuth2.0接口
随机推荐
< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621
< 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
What is erdma? Popular science cartoon illustration
docker mysql
STM32标准固件库函数名(一)
taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享
STM32 standard firmware library function name (I)
mongodb的认识
Openharmony notes --------- (4)
Fabric. JS upper dash, middle dash (strikethrough), underline
数据库连接池和数据源
freemarker的使用
Development and design of animation surrounding mall sales website based on php+mysql
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
String matching problem
go操作redis
[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)
Tencent cloud tstor unified storage passed the evaluation of the first batch of basic file storage capabilities of the ICT Institute
taobao.trade.memo.add( 对一笔交易添加备注 )接口,淘宝店铺插旗接口,淘宝订单插旗API接口,oAuth2.0接口
Essential elements of science fiction 3D scenes - City