mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-24 20:00:37 +00:00
512 B
512 B
Javascript 常用工具封装
类型判断
function type (o) {
return Object.prototype.toString.call(o).toString().slice(8, -1);
}
function sayHi () {
console.log(`Everybody sayHi`);
}
console.log(type(1)) // Number
console.log(type('@航程小刘(http://github.com/FantasticLBP)')) // String
console.log(type(null)) // Null
console.log(type(false)) // Boolean
console.log(type({})) // Object
console.log(type([1,2,3])) // Array
console.log(type(sayHi)) // Function