Comments (2)
function getType(value) {
// 判断数据是 null 的情况
if (value === null) {
return value + "";
}
// 判断数据是引用类型的情况
if (typeof value === "object") {
let valueClass = Object.prototype.toString.call(value),
type = valueClass.split(" ")[1].split("");
type.pop();
return type.join("").toLowerCase();
} else {
// 判断数据是基本数据类型的情况和函数的情况
return typeof value
}
}
from fe-weekly-questions.
处理那一块建议换成 return Object.prototype.toString.call(value).slice(8,-1)
from fe-weekly-questions.
Related Issues (20)
- 如何优化SPA应用的首屏加载速度慢的问题? HOT 6
- Reflect 对象创建目的? HOT 1
- 说说闭包 HOT 2
- 说说事件委托 HOT 4
- 内部属性 [[Class]] 是什么? HOT 3
- 什么是堆?什么是栈?它们之间有什么区别和联系? HOT 1
- JavaScript 有几种类型的值?你能画一下他们的内存图吗? HOT 1
- undefined 与 undeclared 的区别?
- 说几条写 JavaScript 的基本规范? HOT 1
- isNaN 和 Number.isNaN 函数的区别? HOT 1
- 什么情况下会发生布尔值的隐式强制类型转换? HOT 2
- 实现一个页面操作不会整页刷新的网站,并且能在浏览器前进、后 退时正确响应。给出你的技术实现方案? HOT 1
- 剩余参数和 arguments 对象的区别是什么? HOT 2
- 介绍下 BFC、IFC、GFC 和 FFC HOT 1
- 为什么通常在发送数据埋点请求的时候使用的是 1x1 像素的透明 gif 图片? HOT 6
- babel 中的preset 和 plugin代表什么,有什么区别?
- vuex中直接修改state 与 commit来修改state的区别
- 请用 js 去除字符串空格? HOT 1
- 说说TS中type和interface的区别? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe-weekly-questions.