当前位置:网站首页>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.
边栏推荐
- MySql函数
- 测试用例设计方法之等价类划分方法
- Sfdp 超级表单开发平台 V6.0.4 正式发布
- How to switch to root in xshell
- Text classification using huggingface
- [recommended] how to quickly locate a bug during testing
- Quick Pow: 如何快速求幂
- 2022 6 月25 日交易总结
- Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?
- Varnish 基础概览10
猜你喜欢

Cloud, IPv6 and all-optical network

浅析现代Web端im即时通讯开发技术

Sklearn notes: make_ Blobs generate clustering data
![[recommendation system] concise principle and code implementation of user based collaborative filtering](/img/3b/d46e37e7ae245cf2931d32d1ebbe4c.png)
[recommendation system] concise principle and code implementation of user based collaborative filtering

Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture

第八届“互联网+”大赛 | 云原生赛道邀你来挑战

Resizekit2.net size and resolution independent

Is the numpy index the same as the image index?

The first unlucky person watching eth 2.0

Machinery -- nx2007 (UG) finite element analysis tutorial 2 -- assembly
随机推荐
Cloud, IPv6 and all-optical network
Mysql 监控5
Solving plane stress problem with MATLAB
“乘风破浪”的芒果超媒,能上岸吗?
Sentinel source code analysis Part 7 - sentinel adapter module - Summary
Machine learning notes: time series decomposition STL
Varnish 基础概览4
How to unify the use of package manager in a project?
How does webapi relate to the database of MS SQL?
Visual Studio 2017 无法打开包括文件: “QOpenGLFunctions_3_3_Core”: No such file or directory
C language selection, loop overview
[deep learning compilation] operator compilation IR conversion
Three text to speech artifacts, each of which is very practical
【Games101】Transformation
numpy的索引和图片的索引一样吗?
Analysis of IM instant messaging development technology on modern web
【Proteus仿真】8位端口检测8独立按键
Varnish 基础概览5
R语言线性回归模型拟合诊断异常值分析家庭燃气消耗量和卡路里实例带自测题
Can mango hypermedia, which "braves the wind and waves", go ashore?