当前位置:网站首页>判断数据的精确类型
判断数据的精确类型
2022-07-27 14:39:00 【前行的枫】
Object.prototype.toString.call(value)
这不是toString方法吗,转成字符串吗?
其实toString()是object原型上的方法,所有引用类型都能继承它,它返回的是"[object type]",type为object对象类型。

既然引用类型都有这个方法,为什么返回的形式并不都是"[object type]"呢?再来看看mdn
发现大部分重写了toString()方法,也就是说比如数组的原型链有两个toString方法,那么就会继承原型链上离自己最近的方法,所以数组的toString()是转成字符串。要想调用object原型链上的toString(),可以改变this的指向:Object.prototype.toString.call(value)
instanceof :运算符用于某个实例对象的原型链上是否存构造函数的 prototype 属性
typeof : 判断数据类型
这两种方法在判断数据的精确类型上都不准确,如果只是需要判断基本数据类型,typeof就足够。
边栏推荐
- IP protocol of network layer
- 携手SiFive,格兰仕进军半导体领域!两款自研芯片曝光
- CAS compares the knowledge exchanged, ABA problems, and the process of lock upgrading
- Go language slow start -- go operator
- 聊聊面试必问的索引
- Implementation of spark lazy list files
- [Yunxiang book club issue 13] packaging format and coding format of audio files
- Binder initialization process
- [regular expression] match the beginning and end
- C: On function
猜你喜欢

Is low code the future of development? On low code platform
![[sword finger offer] interview question 42: the maximum sum of continuous subarrays -- with 0x80000000 and int_ MIN](/img/01/bbf81cccb47b6351d7265ee4a77c55.png)
[sword finger offer] interview question 42: the maximum sum of continuous subarrays -- with 0x80000000 and int_ MIN

Sword finger offer 51. reverse pairs in the array

C语言:扫雷小游戏

C语言:数据的存储

Three uses of static keyword

C language: custom type

无线网络分析有关的安全软件(aircrack-ng)

UDP message structure and precautions

NPM install error unable to access
随机推荐
leetcode25题:K 个一组翻转链表——链表困难题目详解
Static关键字的三种用法
Catalog component design and custom extended catalog implementation in spark3
IP protocol of network layer
减小程序rom ram,gcc -ffunction-sections -fdata-sections -Wl,–gc-sections 参数详解
Half find
scrapy爬虫框架
Sword finger offer 51. reverse pairs in the array
[sword finger offer] interview question 45: arrange the array into the smallest number
[Yunxiang book club issue 13] common methods of viewing media information and processing audio and video files in ffmpeg
面试重点——传输层的TCP协议
数组名是首元素地址吗?
Spark troubleshooting finishing
[sword finger offer] interview question 53-i: find the number 1 in the sorted array -- three templates for binary search
表格插入行内公式后,单元格失去焦点
UDP message structure and precautions
传美国政府将向部分美企发放对华为销售许可证!
JS operation DOM node
语音直播系统——提升云存储安全性的必要手段
台积电6纳米制程将于明年一季度进入试产