当前位置:网站首页>This in js points to the prototype object
This in js points to the prototype object
2022-07-31 06:00:00 【Messy I】
The JavaScript parser will pass an implicit parameter inside the function every time the function is called. This implicit parameter is this, which points to an object.We call this object the context object of the function execution.Depending on how the function is called, this will point to a different object.
1. When called in the form of a function, this is always window.
2. When called in the form of a method, this is the object that calls the method.
prototype
For each function we create, the parser will add a property prototype to the function, which corresponds to an object, which is what we call a prototype object.
If the function is used as a normal function to call the prototype without any effect, when the function is called in the form of a constructor, the object it creates will have an implicit property, pointing to the prototype object of the constructor, we can pass
span style="color:#ff9900;">__proto__ to access this property.As shown below:
The prototype object is equivalent to a public area. All instances of the same class can access this prototype object. We can uniformly set the common content of the object to the prototype object.
Add property a to the prototype of MyClassSyntax: MyClass.prototype.a=123;
When we access a property or method of an object, it will be found in the object itself, if there is one, it will be used directly, if not, it will be found in the prototype object, and if it is found, it will be used directly.As shown below:
When we create a constructor, we can add the common properties and methods of these objects to the prototype of the constructor, so that we do not need to add each object separately, and it will not affect the global scope.Every object has these properties and methods.
The prototype object of the prototype object...
The prototype object is also an object, so it also has a prototype. When we use the properties or methods of an object, we will find it in itself. If there is one in itself, we will use it directly. If not, we will go to the prototype object to find it. If the prototypeobject, use it.If not then go to the prototype of the prototype to find.Find a as shown below.
The prototype of the object object has no prototype. If it is still not found in the object, undefined is returned.
边栏推荐
- flutter arr dependencies
- SSH automatic reconnection script
- Notes on creating a new virtual machine in Hyper-V
- 【云原生】开源数据分析 SPL 轻松应对 T+0
- understand js operators
- Sqlite column A data is copied to column B
- 阿里一面,说说你知道消息中间件的应用场景有哪些?
- Xiaobai learns reptiles - introduction to reptiles
- DeFi Token in the project management
- cocos2d-x-3.2 不能混合颜色修改
猜你喜欢
The MySQL database in Alibaba Cloud was attacked, and the data was finally recovered
阿里云中mysql数据库被攻击了,最终数据找回来了
[swagger close] The production environment closes the swagger method
浏览器查找js绑定或者监听的事件
GUCCI, LV and other luxury giant universe how to layout yuan, other brands should keep up with?
【windows】--- SQL Server 2008 超详细安装教程
MySQL-如何分库分表?一看就懂
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
NFTs: The Heart of Digital Ownership
Notes on creating a new virtual machine in Hyper-V
随机推荐
A simple bash to powershell case
Tencent Cloud Lightweight Server deletes all firewall rules
Common JVM interview questions and answers
Using IIS10 to build an asp website in win11
sqlmap injection tutorial common commands
powershell statistics folder size
NFTs: The Heart of Digital Ownership
【swagger关闭】生产环境关闭swagger方法
阿里云中mysql数据库被攻击了,最终数据找回来了
Eternal blue bug reappears
mysql启动报错The server quit without updating PID file几种解决办法
CMOS管原理,及其在推挽电路中的应用
MySql创建数据表
[uiautomation] Get WeChat friend list (stored in txt)
常见JVM面试题及答案整理
【云原生】开源数据分析 SPL 轻松应对 T+0
[Elastic-Job] Overview of Distributed Scheduling Tasks
The latest MySql installation teaching, very detailed
podspec自动化升级脚本
The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r