实现检测数据类型的完美方法

function typeof(o){
      var _toString=Object.prototype.toString;
      var _type={
                 "undefined":"undefined",
                 "number":"number",
                 "boolean":"boolean",
                 "string":"string",
                 "[object Function]":"function",
                 "[object Array]":"array",
                 "[object RegExp]":"regexp",
                 "[object Date]":"date",
                 "[object Erroe]":"error"
        }
        return _type[typeof o]||_type[_toString.call(o)]||(o?"object":"null");
}

  

posted on 2017-07-28 18:55  未来-竭尽全力  阅读(145)  评论(0编辑  收藏  举报

导航