封裝type方法例項

靚仔寧發表於2020-12-13

function type (target) {

    var ret = typeof (target);

   var template = {

     "[object Array]" : "array",

     "[object Object]" : "object",

      "[object Number]" : "number - object",

      "[object Boolean]" : "boolean - object",

     "[object String]" : "string -object"

}

   if ( target === null){

    return "null";

} else if (ret == "object"){

  var str = object.prototype.toString.call(target);

  return template[str];

} else {

    return ret;

}

}

相關文章