function getType(obj){
if(obj === null) return String(obj)
return typeof obj === 'object' ?
Object.prototype.toString.call(obj).replace('[object ','').replace(']','').toLowerCase() : typeof obj;
}
console.log(getType(null)); // -> null
console.log(getType(undefined)); // -> undefined
console.log(getType({})); // -> object
console.log(getType([])); // -> array
console.log(getType(123)); // -> number
console.log(getType(true)); // -> boolean
console.log(getType('123')); // -> string
console.log(getType(/123/)); // -> regexp
上一篇

var s1 = "get-element-by-id"
// 转化为 getElementById
var fn = function(s) {
return s.replace(/-\w/g,
2020-05-16
下一篇

8. 字符串转换整数 (atoi)描述
请你来实现一个 atoi 函数,使其能将字符串转换成整数。
首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。接下来的转化规则如下:
如果第一个非空字符为正或者负号时,则
2020-05-16