js变量类型判断 严格通用 Object.prototype.toString.call()
Object.prototype.toString.call()判断结果:
Object.prototype.toString.call(true)
"[object Boolean]"
Object.prototype.toString.call(1)
"[object Number]"
Object.prototype.toString.call(null)
"[object Null]"
Object.prototype.toString.call(undefined)
"[object Undefined]"
Object.prototype.toString.call('ndefined')
"[object String]"
Object.prototype.toString.call([])
"[object Array]"
Object.prototype.toString.call({})
"[object Object]"
Object.prototype.toString.call(alert)
"[object Function]"
Object.prototype.toString.call(/[a-z]/)
"[object RegExp]"
typeof判断结果:
typeof undefined
"undefined"
typeof true
"boolean"
typeof 1
"number"
typeof 'sds'
"string"
typeof alert
"function"
typeof null
"object"
typeof []
"object"
typeof {}
"object"
typeof /[a-z]/
"object"
特别的:(typeof)
new Array(); new Object(); new Boolean(); new RegExp("[a-z]","g");是类似的~
var a = new String('123');
console.log(a);
console.log(Object.prototype.toString.call(a));
console.log(typeof a);
---
var b = new Number(123);
console.log(b);
console.log(Object.prototype.toString.call(b));
console.log(typeof b);
结果为:
String {"123"}
[object String]
object
---
Number {123}
[object Number]
object
js变量类型判断 严格通用 Object.prototype.toString.call()的更多相关文章
- Object.prototype.toString.call()进行类型判断
为什么类型判断用到Object.prototype.toString.call()进行类型判断,而不用typeof()呢? 然后翻了一下资料: Typeof 在使用 ]));/));));//[obj ...
- 【JavaScript】Object.prototype.toString.call()进行类型判断
权声明:本文为博主原创文章,未经博主允许不得转载. op = Object.prototype, ostring = op.toString, ... function isFunction(it) ...
- 类型判断----小白讲解typeof,instanceof,Object.prototype.toString.call()
1.typeof只能判断基本类型数据, 例子: typeof 1 // "number" typeof '1' // "string" typeof true ...
- Object.prototype.toString.call(arg)详解
经常能碰到Object.prototype.toString.call对参数类型进行判断,一开始只知道怎么使用,却不了解具体实现的原理,最近恶补了一下相关知识,写个笔记加强理解,有什么不对的请指教. ...
- js Object.prototype.toString.call()
Object.prototype.toString.call(obj)使用方法以及原理 这几天看vue-router的源码 发现了Object.prototype.toString.call()这 ...
- Object.prototype.toString.call()和typeof()区别
js中判断数据类型都知道用tyoeof(),但是他只能判断object,boolean,function,string,number,undefined还有symbol(es6新增)这几种初步类型,比 ...
- Object.prototype.toString.call(obj)检测数据类型
typeof bar=='object' 不能确切判断数据是一个‘纯粹’的对象 Array null的结果都是object 比较好的方法是: Object.prototype.toString.cal ...
- Object.prototype.toString.call(obj)使用方法以及原理
这几天看vue-router的源码 发现了Object.prototype.toString.call()这样的用法,当时以为这就是转成字符串的用的,但是越看越觉得不太对劲,赶紧查查资料,一查才知道没 ...
- js中通过Object.prototype.toString方法----精确判断对象的类型
判断是否为函数 function isFunction(it) { return Object.prototype.toString.call(it) === '[object Func ...
随机推荐
- String 既然能做性能调优,我直呼内行
码哥,String 还能优化啥?你是不是框我? 莫慌,今天给大家见识一下不一样的 String,从根上拿捏直达 G 点. 并且码哥分享一个例子:通过性能调优我们能实现百兆内存轻松存储几十 G 数据. ...
- Python_string.Template的使用
Template是python string提供的一个字符串模板功能.主要用于文本处理 from string import Template s = Template('$who 在 $do') t ...
- Flask_环境部署(十六)
flask自带的服务器,无法满足性能要求,我们这里采用Gunicorn做wsgi容器,来部署flask程序并使用 Nginx 做前端代理实现分流.转发.负载均衡,以及分担服务器的压力. Gunicor ...
- lombok不支持enum类型
今天在使用枚举时想着少写getter方法和构造方法,结果加上注解后说是只支持class类型 来自为知笔记(Wiz)
- django中使用支付宝
一.注册 https://auth.alipay.com/login/ant_sso_index.htm?goto=https%3A%2F%2Fopenhome.alipay.com%2Fplatfo ...
- JS 判断上传文件类型
var video_src_file = $("#video_src_file").val(); var fileTypes = new Array("flv" ...
- 《手把手教你》系列技巧篇(五十七)-java+ selenium自动化测试-下载文件-下篇(详细教程)
1.简介 前边几篇文章讲解完如何上传文件,既然有上传,那么就可能会有下载文件.因此宏哥就接着讲解和分享一下:自动化测试下载文件.可能有的小伙伴或者童鞋们会觉得这不是很简单吗,还用你介绍和讲解啊,不说就 ...
- MASA Framework - EventBus设计
目录 MASA Framework - 整体设计思路 MASA Framework - EventBus设计 概述 利用发布订阅模式来解耦不同架构层级,亦可用于解决隔离业务之间的交互 优点: 松耦合 ...
- leetcode 1541. 平衡括号字符串的最少插入次数
问题描述 给你一个括号字符串 s ,它只包含字符 '(' 和 ')' .一个括号字符串被称为平衡的当它满足: 任何左括号 '(' 必须对应两个连续的右括号 '))' . 左括号 '(' 必须在对应的连 ...
- 网络编程-跨域资源共享 CORS
目录 1.什么是同源策略? 2.跨域资源共享 CORS 3.预检请求 4.CORS相关字段 5.Golang实现跨域 6.参考资料 1.什么是同源策略? 如果两个 URL 的 protocol.por ...