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

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");
}

  

原文地址:https://www.cnblogs.com/hjdjs/p/7252124.html