_.isFunction(a) vs. typeof a === 'function'? javascript

前端 未结 2 1875
失恋的感觉
失恋的感觉 2020-12-14 05:54

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

And seems that typeof is faster.

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 06:06

    There is no reason not to use typeof.

    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" :

    enter image description here

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

提交回复
热议问题