_.isFunction(a)与==='function'的类型? JavaScript的 [英] _.isFunction(a) vs. typeof a === 'function'? javascript

查看:196
本文介绍了_.isFunction(a)与==='function'的类型? JavaScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这可能只是性能问题 - http://jsperf.com/ compare-underscore-js-isfunction-with-typeof-function / 2

I think it might be only performance case - http://jsperf.com/comparing-underscore-js-isfunction-with-typeof-function/2

似乎 typeof 更快..所以我的问题是 - 哪个更适合使用?

And seems that typeof is faster.. so my question is - which is more appropriate to use?

推荐答案

没有理由不使用 typeof

不仅速度快,而且ECMAScript规范确保所有函数都具有函数类型,并且只有函数可以具有函数类型:

Not only is it faster but the ECMAScript specification ensures that all functions have a type of "function" and that only functions can have a type of "function" :

此运算符为专门设计用于获取值的类型,为什么不使用它?

This operator was specifically designed to get the type of a value, so why not use it ?

这篇关于_.isFunction(a)与==='function'的类型? JavaScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆