当前位置:网站首页>JS prototype and prototype chain (Lantern Festival meal)
JS prototype and prototype chain (Lantern Festival meal)
2022-06-30 01:23:00 【Madrid Tianxin】
Today is the Lantern Festival , I wish you all a happy Lantern Festival ! Today, let's talk about prototype and prototype chain ~
First of all, we make it clear that the prototype exists in the constructed functions , Arrays and classes have no prototype ~
So let's start with the constructor , Then add some attributes to the function prototype to test .
function person(){
this.say=function(){
console.log(" In the constructor ");
}
}In the existing function person Prototype under prototype Add attribute to test .
person.prototype.say=function(){
console.log(" Functions in the prototype ");
} When all the above is done, we will start Create examples And directly create a name attribute :
var p1 = new person();
p1.name=" Li Si ";
Then create on the prototype name And age attribute :
person.prototype.name=" Zhang San ";
person.prototype.age = 18;
After all the above steps are completed , We can start testing !

Background printing ,say The method calls in the constructor ;age Is in the prototype ;name It's an example of .
It can be explained in this way , The background is to find the current instance attribute first , If you find it , Then print it out , If it is not found, it will follow the prototype chain layer by layer , Finally, if the value found in the prototype chain is null Print out in the background undefined.
边栏推荐
- Quick pow: how to quickly find power
- Stimulus reports reporting tool, stimulus creates and builds reports
- post请求出现WebKitFormBoundaryk的解决办法
- Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?
- Mysql 监控
- 在线SQL转CSV工具
- Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
- 2022-06-29:x = { a, b, c, d }, y = { e, f, g, h }, x、y两个小数组长度都是4。 如果有: a + e = b + f = c + g = d + h
- 如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要
- Interface Association of postman
猜你喜欢

How to refuse the useless final review? Ape tutoring: it is important to find a suitable review method

In depth analysis of a large number of clos on the server_ The root of wait

Application of pointer in STC89C52 single chip microcomputer and demonstration of practical cases
![[Thesis Writing] English thesis writing guide](/img/59/88d34814a88a2da19ed6a236825649.png)
[Thesis Writing] English thesis writing guide

2022 6 月25 日交易总结

SFDP super form development platform v6.0.4 was officially released

How did the data center change from "Britney Spears" to "Mrs. bull"?

清洁、对话、带娃,扫地机摆脱“人工智障”标签

数字垃圾是什么?跟随世界第一位AI艺术家,探索元碳艺术

UDP servers and clients in go
随机推荐
MySql函数
Sentinel source code analysis Part 8 - core process - sphu Entry current limiting execution
Transaction summary on June 25, 2022
ResizeKit2.NET大小和分辨率独立
Solution to webkitformboundaryk in post request
传统微服务框架如何无缝过渡到服务网格 ASM
【Games101】Transformation
How to seamlessly transition from traditional microservice framework to service grid ASM
Is the course of digging money reliable and safe to open an account?
C language final without failing (Part 1)
【论文写作】英文论文写作指南
How did the data center change from "Britney Spears" to "Mrs. bull"?
Seata et les trois plateformes travaillent main dans la main pour programmer Summer, un million de bonus vous attend
存储引擎分析
Cantilever beam calculation [matlab code]
MES管理系统功能模块之质量管理
Stringredistemplate disconnects and the value disappears
“乘风破浪”的芒果超媒,能上岸吗?
numpy的索引和图片的索引一样吗?
The Web3 era is coming? Inventory of five Web3 representative projects | footprint analytics