当前位置:网站首页>三十一. `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
边栏推荐
- 论文写作 19: 会议论文与期刊论文的区别
- R language ggplot2 visualization: ggplot2 visualizes the scatter diagram and uses geom_ mark_ The ellipse function adds ellipses around data points of data clusters or data groups for annotation
- SRS deployment
- Plato Farm元宇宙IEO上线四大,链上交易颇高
- Fundamentals of network communication (LAN, Wan, IP address, port number, protocol, encapsulation and distribution)
- Intersection calculation of straight line and plane in PCL point cloud processing (53)
- Tencent Qiu Dongyang: techniques and ways of accelerating deep model reasoning
- Common form verification
- How to protect ECs from hacker attacks?
- Research on open source OCR engine
猜你喜欢
Numpy mathematical function & logical function
DTMF dual tone multi frequency signal simulation demonstration system
考研英语唐叔的语法课笔记
Leetcode dynamic planning training camp (1-5 days)
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Click an EL checkbox to select all questions
[target tracking] pedestrian attitude recognition based on frame difference method combined with Kalman filter, with matlab code
An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
MySQL advanced lock - overview of MySQL locks and classification of MySQL locks: global lock (data backup), table level lock (table shared read lock, table exclusive write lock, metadata lock and inte
Linux64Bit下安装MySQL5.6-不能修改root密码
随机推荐
Remote code execution in Win 11 using wpad / PAC and JScript 3
STM32 Basics
AQS learning
Leetcode dynamic planning training camp (1-5 days)
Sqoop imports tinyint type fields to boolean type
DNS cloud school rising posture! Three advanced uses of authoritative DNS
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
Plato Farm元宇宙IEO上线四大,链上交易颇高
star
JDBC tool class jdbcconutil gets the connection to the database
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
如何做产品创新?——产品创新方法论探索一
Tencent Qiu Dongyang: techniques and ways of accelerating deep model reasoning
Solution to PowerDesigner's failure to connect to MySQL in x64 system
nc基础用法2
R语言使用timeROC包计算无竞争风险情况下的生存资料多时间AUC值、使用confint函数计算无竞争风险情况下的生存资料多时间AUC指标的置信区间值
[talkative cloud native] load balancing - the passenger flow of small restaurants has increased
Some basic configurations in interlij idea
ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
Customize timeline component styles