PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
数组
ECMAScript5中Array.isArray是原生的判断数组的方法,IE9及以上支持。考虑到兼容性,在没有此方法的浏览器中,可以使用 Object.prototype.toString.call(obj) === '[object Array]'替代。
var isArray = Array.isArray || function(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }
JQ的确封装了一个函数jQuery.inArray( value, array ) 搜索数组中指定值并返回它的索引(如果没有找到则返回-1)。
value要搜索的值。array一个数组,通过它来搜索。
function inArray1(needle,array,bool){ if(typeof needle=="string"||typeof needle=="number"){ for(var i in array){ if(needle===array[i]){ if(bool){ return i; } return true; } } return false; } }
函数
最简单且性能最好的办法就是 typeof obj == 'function'。考虑到某些版本浏览器存在的bug,最靠谱的办法是 Object.prototype.toString.call(obj) === '[object Function]'。
var isFunction = function(obj) { return Object.prototype.toString.call(obj) === '[object Function]'; } if(typeof /./ != 'function' && typeof Int8Array != 'object') { isFunction = function(obj) { return typeof obj == 'function'; } }
对象
在JavaScript中复杂类型是对象,函数也是对象。对上述2者使用typeof,可以分别得到'object'和'function'。另外,还要排除null值的情况,因为typeof null 得到的也是 'object'。
var isObject = function(obj) { var type = typeof obj; return type === 'function' || type === 'object' && !!obj; }
已抢7213个
抢已抢94860个
抢已抢14828个
抢已抢52089个
抢已抢194766个
抢已抢87280个
抢