学习type of和instanceof
来源:互联网 发布:json expecting eof 编辑:程序博客网 时间:2024/06/06 01:41
type of 返回5种类型number,boolean,string,object,undefined,function
type of 常用技巧:判断一个变量是否存在if(typeof a != 'undefined'){};
切记instanceof只能用来判断对象和函数,不能用来判断字符串和数字等,a instanceof Array 返回布尔值
判断数组的方法
1.
var arr = [1,2,3,1];
alert(arr.constructor === Array); // true
2.
var arr = [1,2,3];
alert(arr instanceof Array); // true
封装检测是否是数组的方法var arr = [1,2,3];
function isArrayFn(obj){ //封装一个函数
if (typeof Array.isArray === "function") {
return Array.isArray(obj); //浏览器支持则使用isArray()方法
}else{ //否则使用toString方法
return Object.prototype.toString.call(obj) === "[object Array]";
}
}
alert(isArrayFn(arr));// true
阅读全文
0 0
- 学习type of和instanceof
- CSS3中nth-of-type和nth-last-of-type
- The Type Comparison Operator instanceof
- The Type Comparison Operator instanceof
- of-type和child的区别
- nth-child和nth-of-type区别
- 浅谈:nth-child和:nth-of-type
- :nth-child和:nth-of-type
- java日常学习:instanceof、final和抽象类
- 从一个例子学习 instanceof 和 getclass 的区别
- jQuery 选择器 first-child和first-of-type、 last-child和last-of-type的区别
- JAVA-学习-instanceof
- instanceOf学习笔记
- jQuery选择器中last-of-type和first-of-type效果案例
- CSS选择器 first-child 、first-of-type 和 nth-of-type()
- instanceof和Class.isInstance()
- Javascript typeof 和instanceof
- class.isAssignableFrom 和 instanceof
- JAVA内存模型和线程安全
- 使用 Vuex + axios 发送请求
- ListView的Item包含checkBox的时候的点击事件
- NGUI Panel Soft Clip原理分析
- 分布式系统是什么,分布式计算的优缺点有哪些?
- 学习type of和instanceof
- iOS app被拒------支付功能审核被拒(虚拟产品)Guideline 3.1.1
- Python实证式算法评估
- Linux系统UID和GID详解
- GPML toolbox -- document
- const知识点总结
- Flash与文件系统
- HDU-5980-水题-二进制转换
- hashSet判断是否是同一对象