当前位置:网站首页>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.
边栏推荐
- C language tutorial (3) - if and loop
- Common JVM interview questions and answers
- "limit" query in Oracle database
- A simple bash to powershell case
- The latest MySql installation teaching, very detailed
- [Cloud native] Open source data analysis SPL easily copes with T+0
- Gradle sync failed: Uninitialized object exists on backward branch 142
- NFTs: The Heart of Digital Ownership
- jenkins +miniprogram-ci 一键上传微信小程序
- Chinese garbled solution in UTF-8 environment in Powershell
猜你喜欢

The server time zone value ‘й‘ is unrecognized or represents more than one time zone

MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案

UiBot has an open Microsoft Edge browser and cannot perform the installation

MySQL面试题大全(陆续更新)

npm WARN config global `--global`, `--local` are deprecated. Use `--location解决方案

Using IIS10 to build an asp website in win11

flutter 混合开发 module 依赖
![[Cloud Native] What should I do if SQL (and stored procedures) run too slowly?](/img/40/be3a30743ee2bc6c82f82ab852f29c.png)
[Cloud Native] What should I do if SQL (and stored procedures) run too slowly?
![[windows]--- SQL Server 2008 super detailed installation tutorial](/img/b7/dc802c63b07edc4298b6e6b90d865c.png)
[windows]--- SQL Server 2008 super detailed installation tutorial

MySQL高级SQL语句(二)
随机推荐
Linux modify MySQL database password
Flow control statement in js
MySQL-如何分库分表?一看就懂
cocos create EditBox 输入文字被刘海屏遮挡修改
The server time zone value ‘й‘ is unrecognized or represents more than one time zone
podspec自动化升级脚本
理解js运算符
Markdown help documentation
this points to the problem
Several solutions for mysql startup error The server quit without updating PID file
understand js operators
On the side of Ali, tell me what are the application scenarios of message middleware you know?
Filter out egrep itself when using ps | egrep
js中的函数
sql add default constraint
360 加固 file path not exists.
Error: Cannot find module 'D:\Application\nodejs\node_modules\npm\bin\npm-cli.js'
Chinese garbled solution in UTF-8 environment in Powershell
CMOS管原理,及其在推挽电路中的应用
Yuan prospect and four track of the universe