mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-25 04:17:17 +00:00
20 lines
512 B
Markdown
20 lines
512 B
Markdown
# Javascript 常用工具封装
|
|
|
|
## 类型判断
|
|
|
|
```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
|
|
``` |