方式 | 语法 | 优点 | 缺点 |
---|---|---|---|
typeof | typeof(data) typeof data | 返回结果为js基本的数据类型,包括umber、boolean、string、object、undefined、function | 不能判断null、array、regexp、自定义类 |
constructor | data.constructor | 能判断自定义类 | 不能判断Null、Undefined |
Object.propotype.toString.call() | Object.propotype.toString.call(data) | 支持Sring、Array、Number、Boolean、Object、Regexp、Function、Object、Null、Undefined | 不能判断自定义类 |
JavaScript中类型判断:typeof、constructor、Object.propotype.toString.call()的比较
最新推荐文章于 2022-06-19 10:03:22 发布