数据类型 constructor
来源:互联网 发布:网络调查的方法与步骤 编辑:程序博客网 时间:2024/05/19 16:48
constructor属性是可以改写的,如果你一不小心作死改了constructor属性的话,那么使用这种方法就无法判断出数组的真是身份了,
const a = [];
console.log(a.constructor);//function Array(){ [native code] }
//定义一个数组
const a = [];
//作死将constructor属性改成了别的
a.contrtuctor = Object;
console.log(a.constructor == Array);//false (哭脸)
console.log(a.constructor == Object);//true (哭脸)
console.log(a instanceof Array);//true (instanceof火眼金睛)
可以看出,constructor属性被修改之后,就无法用这个方法判断数组是数组了,除非你能保证不会发生constructor属性被改写的情况,否则用这种方法来判断数组也是不靠谱的。
const a = [];
console.log(a.constructor);//function Array(){ [native code] }
//定义一个数组
const a = [];
//作死将constructor属性改成了别的
a.contrtuctor = Object;
console.log(a.constructor == Array);//false (哭脸)
console.log(a.constructor == Object);//true (哭脸)
console.log(a instanceof Array);//true (instanceof火眼金睛)
可以看出,constructor属性被修改之后,就无法用这个方法判断数组是数组了,除非你能保证不会发生constructor属性被改写的情况,否则用这种方法来判断数组也是不靠谱的。
0 0
- 数据类型 constructor
- Constructor
- Constructor
- constructor
- constructor
- constructor
- constructor
- constructor
- js 检测数据类型instanceof/constructor和 Object.prototype.toString.call()
- typeof + instanceof+toString+constructor是如何判断javascript数据类型的
- js中判断数据类型的属性typeof、instanceof、 constructor、 prototype
- 如何判断js中的数据类型:typeof、instanceof、 constructor、 prototype方法比较
- javascript中判断数据类型的四种方法及typeof、instanceof、constructor、toString
- Constructor or not constructor?
- Default Constructor && Copy Constructor
- default constructor
- webkit constructor
- virtual constructor
- CSS3选择器容易误解的点
- 数据类型 typeof
- 微信企业号自定义菜单拉取信息的实现
- hdu 2485 Destroying the bus stations【最大流Dinic+最短路floyd】好题
- Redis的主从复制
- 数据类型 constructor
- 阿里云sls日志服务的简单监控 php实现
- android客户端与服务器端socket通信
- 数据类型 instanceof
- 框架(一)布局
- Maven国内源设置 - OSChina国内源失效了,别更新了
- 一句英文中,单词最长的那个
- 【python】centos6安装python3
- iOS 浅赋值、深复制、完全复制的知识点梳理验证(附加归档解档)