【javascript】——封装typeof

xiaoge00 2020-01-05

function typeOf(value) {
  var ret = typeof(value);
  var template = {
    "[object Array]": "array",
    "[object Object]": "object",
      "[object Number]": "number - object",
    "[object Boolean]": "boolean - object",
    "[object String]": "string - object"
  }
  if (value === null) {
    return null;
  }else if (ret == ‘object‘) {
    var str = Object.prototype.toString.call(value);
    return template[str];
  }else {
    return ret;
  }
}

相关推荐