typeOf函数加强版

[javascript] //肥主流版本 function typeOf(o) { var t;return (t = typeof(o)) == "object" ? o==null && "null" || Object.prototype.toString.call(o).slice(8,-1):t; } //和谐版本 function typeOf(o) { var t; if((t = typeof(o)) == "object"){ if(o==null) t = 'null'; else t = Object.prototype.toString.call(o).slice(8,-1); } return t; } //执行结果 typeOf("abc"); //string typeOf(true); //boolean typeOf(123); //number typeOf([]); //array typeOf({}); //object typeOf(function(){}); //function typeOf(new Date); //date typeOf(new RegExp); //regexp typeOf(Math); //math typeOf(null); //null [/javascript]
posted @ 2010-09-08 09:30  7hihi  阅读(172)  评论(0编辑  收藏  举报