当前位置:网站首页>三十一. `prototype`显示原型属性和`__proto__`隐式原型属性
三十一. `prototype`显示原型属性和`__proto__`隐式原型属性
2022-04-23 20:21:00 【这不比博人传燃?】
这个是属于js中的知识。
1. js中创建对象的几种(4种)方式:
我们先来了解一下js中创建对象的几种(4种)方式:
- 通过Object()方法来创建
- 通过字面量法创建对象
- 通过自定义函数创建对象
- 通过工厂模式创建对象
参考:https://blog.csdn.net/dearzhuoer/article/details/84574140
我们来看看第三种方式你就知道了——通过函数创建!!!
什么意思?函数就是对象?不错!!!
2. 函数就是对象?
- 在js中对象就是神一般的存在,什么都是对象(包括函数),你就这么理解好了。
- 我们创建的每一个函数,解析器都会向函数中添加一个属性
prototype(除了一些内建函数)。这个属性是一个指针,指向一个原型对象。(也可以这个属性对应这个一个原型对象——prototype:原型对象) - 若这个函数作为普通函数,则这个
prototype属性没有任何作用;但若这个函数作为构造函数用于创造对象,则这个对象会有一个隐含属性__proto__,这个隐含属性__proto__也指向这个原型对象。
所以有了以下结论:构造函数名.prototype=对象名.__proto__
参考:https://blog.csdn.net/dong001687/article/details/81836575
3. prototype和__proto__
prototype:显示原型属性
__proto__:隐式原型属性
至于为什么一个显示,一个隐式,看了上面第二点我们也知道了。prototype可见,__proto__不可见。
4. 举例:
function Mytest(name,age){
this.name = name;
this.age = age;
}
var xiaoming = new Mytest('小明',18)
console.log(Mytest.prototype) //{constructor: ƒ}
console.log(xiaoming.__proto__) //undefined
console.log(Mytest.prototype==xiaoming.__proto__) //true
版权声明
本文为[这不比博人传燃?]所创,转载请带上原文链接,感谢
https://blog.csdn.net/HSH541/article/details/124351759
边栏推荐
- NC basic usage
- Livego + ffmpeg + RTMP + flvjs to realize live video
- nc基础用法4
- R语言使用timeROC包计算无竞争风险情况下的生存资料多时间AUC值、使用confint函数计算无竞争风险情况下的生存资料多时间AUC指标的置信区间值
- Investigate why close is required after sqlsession is used in mybatties
- JDBC tool class jdbcconutil gets the connection to the database
- 考研英语唐叔的语法课笔记
- Some basic configurations in interlij idea
- [problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
- NC basic usage 2
猜你喜欢

WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website

Servlet learning notes
![[graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph](/img/fb/9822cccde4ca39d8066024c09a7349.png)
[graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph

Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report

Installation and use of NVM

Mysql database backup scheme

Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
![[latex] 5 how to quickly write out the latex formula corresponding to the formula](/img/1f/3c5a332ce1d6852dde38040faea5bf.png)
[latex] 5 how to quickly write out the latex formula corresponding to the formula
![[talkative cloud native] load balancing - the passenger flow of small restaurants has increased](/img/ba/4ccf0c2181572fed16bbc9c797d557.png)
[talkative cloud native] load balancing - the passenger flow of small restaurants has increased

堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
随机推荐
Click an EL checkbox to select all questions
R语言ggplot2可视化:ggplot2可视化散点图并使用geom_mark_ellipse函数在数据簇或数据分组的数据点周围添加椭圆进行注释
Redis distributed lock
CVPR 2022 | QueryDet:使用级联稀疏query加速高分辨率下的小目标检测
Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 127
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
Operation of numpy array
論文寫作 19: 會議論文與期刊論文的區別
JDBC tool class jdbcconutil gets the connection to the database
R language uses timeroc package to calculate the multi time AUC value of survival data under competitive risk, uses Cox model and adds covariates, and R language uses the plotauccurve function of time
CVPR 2022 | querydet: use cascaded sparse query to accelerate small target detection under high resolution
Local call feign interface message 404
R语言使用timeROC包计算无竞争风险情况下的生存资料多时间AUC值、使用confint函数计算无竞争风险情况下的生存资料多时间AUC指标的置信区间值
Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
Redis installation (centos7 command line installation)
SRS deployment
Tensorflow 2 basic operation dictionary
Implementation of mypromise
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions