标签:
在JavaScript中,内置的类型检测机制并非是完全可靠的。这里分别指的typeof和instanceof关键字。var isArray = value instanceof Array;
console.log(Object.prototype.toString.call([]));//[object Array] console.log(Object.prototype.toString.call(window.Array));//[object function] console.log(Object.prototype.toString.call(Object));//[object function] console.log(Object.prototype.toString.call(window));//[object global] console.log(Object.prototype.toString.call(/^\d/));//[object RegExp] console.log(Object.prototype.toString.call(new Object()));//[object Object]
function isFunction(value){ return Object.prototype.toString.call(value)=="[object Function]"; }
标签:
原文地址:http://blog.csdn.net/gua_381091614/article/details/45728145