获取对象的类型,

1js中引用类型typeOf返回值为object;

var b=[]

function getObjType(obj){

return typeof(obj)!=="function"?

undefined:

obj.name||/function (.+?)\(/.exec(obj+"")[1]

//if(obj.name){

//return obj.name //ie8 不支持

//}else{

//var str=(""+b.constructor).replace(/\s/g,"").replace("function","");

//return (str.match(/\w+\(/)+"").replace('(',"")

//return /function (.+?)\(/.exec(obj+"")[1]

}

}

var s=getObjType(b.constructor)

console.log(s)

猜你喜欢

转载自www.cnblogs.com/ypwei/p/9013699.html
今日推荐