当前位置:网站首页>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.
边栏推荐
- sqlmap injection tutorial common commands
- Digital twins will be an important way to enter the "metaverse"
- flutter arr 依赖
- cocoscreator 显示刘海内容
- A simple bash to powershell case
- SSH automatic reconnection script
- What is the difference between NFT and digital collection?
- Artifact SSMwar exploded Error deploying artifact.See server log for details
- 腾讯云GPU桌面服务器驱动安装
- 场效应管 | N-mos内部结构详解
猜你喜欢
随机推荐
MySQL压缩包方式安装,傻瓜式教学
Several solutions for mysql startup error The server quit without updating PID file
Regular Expression Basics
动态规划(一)| 斐波那契数列和归递
What is the difference between NFT and digital collection?
浏览器查找js绑定或者监听的事件
TransactionTemplate 事务编程式写法
2021 Mianjing - Embrace Change
MySql to create data tables
理解js运算符
2021美赛C题M奖思路
unicloud 发布后小程序提示连接本地调试服务失败,请检查客户端是否和主机在同一局域网下
this points to the problem
quick-3.6源码修改纪录
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
MySql创建数据表
mysql password modification method in Linux (pro-test available)
[Elastic-Job] Overview of Distributed Scheduling Tasks
【云原生】开源数据分析 SPL 轻松应对 T+0
[uiautomation] Get WeChat friend list (stored in txt)









