梦太阳 2022-05-04 13:50:49
type API 个人感觉这么写更好些~
const typeMap = "Symbol Boolean Number String Function Array Date RegExp Object Error" .split(" ") .reduce((prev, item) => { prev[`[object ${item}]`] = item.toLowerCase(); return prev; }, {}); function type(obj) { //解决IE6 中的兼容 if(null == obj) return '' + obj; return typeof obj !== "object" ? typeof obj : typeMap[Object.prototype.toString.call(obj)] || 'object'; }
- 共 1 页
- 1
我觉着这个还是得加一些异常case,比如1000,或者负数
第 99 题:编程算法题