当前位置:网站首页>三十一. `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
边栏推荐
- Rédaction de thèses 19: différences entre les thèses de conférence et les thèses périodiques
- Es index (document name) fuzzy query method (database name fuzzy query method)
- Servlet learning notes
- RT-1052学习笔记 - GPIO架构分析
- DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
- Tencent Qiu Dongyang: techniques and ways of accelerating deep model reasoning
- NC basic usage 1
- 网络通信基础(局域网、广域网、IP地址、端口号、协议、封装、分用)
- ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
- 16MySQL之DCL 中 COMMIT和ROllBACK
猜你喜欢
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
Commit and rollback in DCL of 16 MySQL
DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
WordPress插件:WP-China-Yes解决国内访问官网慢的方法
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
波场DAO新物种下场,USDD如何破局稳定币市场?
Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
Development of Matlab GUI bridge auxiliary Designer (functional introduction)
随机推荐
Openharmony open source developer growth plan, looking for new open source forces that change the world!
波场DAO新物种下场,USDD如何破局稳定币市场?
Tencent Qiu Dongyang: techniques and ways of accelerating deep model reasoning
Numpy sort search count set
本地调用feign接口报404
Is the wechat CICC wealth high-end zone safe? How to open an account for securities
What is the difference between a host and a server?
【PTA】L1-006 连续因子
Remote code execution in Win 11 using wpad / PAC and JScript 1
R语言survival包coxph函数构建cox回归模型、ggrisk包ggrisk函数和two_scatter函数可视化Cox回归的风险评分图、解读风险评分图、基于LIRI数据集(基因数据集)
Numpy - creation of data type and array
How about CICC fortune? Is it safe to open an account
Servlet learning notes
NC basic usage 1
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Cadence Orcad Capture 批量更改元件封装功能介绍图文教程及视频演示
An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
Recommend an open source free drawing software draw IO exportable vector graph
Identification of bolt points in aerial photography based on perception
BMP JPEG 图片转换为矢量图像 ContourTrace