当前位置:网站首页>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: 如何快速求幂
- Using tsne to visualize the similarity of different sentences
- Shell spec date format
- How to switch to root in xshell
- Resizekit2.net size and resolution independent
- What if you can't write your composition well? Ape counseling: parents should pay attention to these points
- Mysql 监控3
- Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)
- Equivalence class partition method for test case design method
- Internal class usage scenarios, syntax and principle explanations
猜你喜欢

Ansible ad-hoc 临时命令

Online sql to CSV tool

How to seamlessly transition from traditional microservice framework to service grid ASM

Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?

Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)

在线文本数字识别列表求和工具

Statsmodels notes STL

2020-12-03

Pytroch Learning Notes 6: NN network layer convolution layer

How latex enters a matrix
随机推荐
Stimulus reports reporting tool, stimulus creates and builds reports
STC89C52 single chip microcomputer simple calculator design and code demonstration
81. search rotation sort array II
Seata 与三大平台携手编程之夏,百万奖金等你来拿
Quick Pow: 如何快速求幂
2022-06-29: x = {a, B, C, D}, y = {e, F, G, H}, the length of the two small arrays X and Y is 4. If yes: a + e = B + F = C + G = D + H
[MRCTF2020]Ezpop-1|php序列化
Stringredistemplate disconnects and the value disappears
眼底出血术后需注意事项//每天必看
【Games101】Transformation
Storage engine analysis
Machine learning notes: time series decomposition STL
shell 规范日期格式
一文读懂,MES管理系统模块功能
How to seamlessly transition from traditional microservice framework to service grid ASM
Understand the module function of MES management system
Precautions for postoperative fundus hemorrhage / / must see every day
【深度学习编译】算子编译 IR 转换
在线SQL转CSV工具
Online sql to CSV tool