mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-25 12:27:15 +00:00
docs: 批量博文
This commit is contained in:
20
Chapter2 - Web FrontEnd/2.30.md
Normal file
20
Chapter2 - Web FrontEnd/2.30.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# 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
|
||||
```
|
||||
Reference in New Issue
Block a user