IFE_part2_JavaScript_实践判断各种数据类型的方法
实践判断各种数据类型的方法:
// 判断arr是否为一个数组,返回一个bool值
function isArray(arr) {
// typeof办法并不能实时的检测出是否是数组,只能判断其类型
// console.log(typeof arr == "array");
console.log(arr instanceof Array)
}
// 判断fn是否为一个函数,返回一个bool值
function isFunction(fn) {
// instanceof 后面一定要是对象类型,并且大小写不能错,该方法适合一些条件选择或分支。
console.log(fn instanceof Function)
}
// 另外的方法:
// 1.typeof /typeof 可以判断function的类型;在判断除Object类型的对象时比较方便。
// 2.constructor
// 3.prototype /Object.prototype.toString.call(a) === ‘[object String]’
// 4.jquery.type()
参考链接:判断js中数据类型的几种方法

浙公网安备 33010602011771号