当前位置:网站首页>How exactly does instanceof judge the reference data type!
How exactly does instanceof judge the reference data type!
2022-06-11 06:28:00 【Saucey_ six】
Procrastination .... It has to be cured !( Just began to sum up the problems encountered in the autumn moves )
The problem is that :
Judge JavaScript Methods of data type :( Okay , Just write it down )
- The most common :typeof Judge , But its drawback is , The types returned are all in string form
typeof null ===object,- It cannot judge
Arraytype , The determined array type is Object.
- When the object type is known :instanceof
that , So the question comes ,instanceof How to judge .
- Based on the constructor Judge :constructor
- constructor Property returns an array that creates this object , References to functions .
Object.prototype.toString.call()==='[object Array]'To judge . Universal , But it's troublesome .
instanceof How to judge the reference type .
The first reaction is to inherit , But I seem to think too much .
Look at a piece of code :
function A(){}
let a = new A()
console.log(a instanceof A)//true
Obviously instanceof Is to judge whether an instance belongs to a certain type
Of course it's clear ,instanceof You can determine whether an instance belongs to its parent type in the inheritance relationship .
function instance_of(L, R) {
var O = R.prototype;// R The display prototype of
L = L.__proto__;// L The implicit prototype of
while (true) {
/* Object.prototype.__proto__ === null*/
/* __proto__ Point to its prototype object */
if (L === null) {
return false
}
if (L === O) {
return true
}
L = L.__proto__;
}
}
all JavaScript Object has proto attribute , But only Object.prototype.proto by null, The premise is that it is not Firefox perhaps Chrome I have modified this property . This property points to its prototype object .
ok, About the same , We continue .
Push : Object instanceof Object
ObjectL = Object, ObjectR = Object;
O = ObjectR.prototype = Object.prototype
L = ObjectL.__proto__ = Function.prototype
// For the first time
O !== L
L = Function.prototype.__proto__ = Object.prototype// Loop search L Is there any more __proto__
// Second judgment
O === L// return true
边栏推荐
- 通过R语言且只用基础package来制作一个小游戏
- Basic use of BufferedReader and bufferedwriter
- On the social moral and ethical issues behind short videos (personal point of view, for reference only)
- What are the differences and usages of break and continue?
- Squid agent
- 个人常用软件及浏览器插件分享
- Chapter 4 of machine learning [series] naive Bayesian model
- Wechat applet (authorized login) (not recommended, click the home page to view the updated authorized login)
- C language war "minesweeping"
- A multi classification model suitable for discrete value classification -- softmax regression
猜你喜欢

FPGA面试题目笔记(一)——FPGA开发流程、亚稳态和竞争冒险、建立保持时间、异步FIFO深度等

Sqli-labs less-01

break,continue有什么区别和用法?

FPGA面试题目笔记(三)——跨时钟域中握手信号同步的实现、任意分频、进制转换、RAM存储器等、原码反码和补码
![[]==![]](/img/65/ab724c74b080da319ed5c01c93fdb7.png)
[]==![]

Autojs, read one line, delete one line, and stop scripts other than your own

verilog实现双目摄像头图像数据采集并modelsim仿真,最终matlab进行图像显示

MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation
![[reading this article is enough!!! Easy to understand] confidence level understanding (95% confidence level and confidence interval)](/img/d6/e61ba5bad2b2847378c4547ce0780d.jpg)
[reading this article is enough!!! Easy to understand] confidence level understanding (95% confidence level and confidence interval)

Simple knapsack problem
随机推荐
ijkPlayer中的错误码
Build the first power cloud platform
Human gene editing technology and ethical issues behind it [personal view, for reference only]
不引入第三个变量,交换两个值
Chapter 4 of machine learning [series] naive Bayesian model
FMT package usage of go and string formatting
jenkins-不同风格的项目构建
instanceof到底是怎样判断引用数据类型的!
What is sentinel produced by Ali?
Matlab实现均值滤波与FPGA进行对比,并采用modelsim波形仿真
FPGA interview topic notes (I) - FPGA development process, metastable state and competitive risk, build and hold time, asynchronous FIFO depth, etc
Growth Diary 01
Instanceof and type conversion
Sqoop installation tutorial
FIFO最小深度计算的题目合集
Stock K-line drawing
021 mongodb database from getting started to giving up
100. 相同的树
021-MongoDB数据库从入门到放弃
PHP laravel8 send email